Class PrimeTestClock
NodaTime partial of PrimeTestClock: NodaTime.Instant storage, zone-aware "now" surfaces, and NodaTime.Duration overloads that forward to the shared march and runner implementation.
public sealed class PrimeTestClock : PrimeTestTimeBase, IPrimeTestClock, IPrimeTestTime, IPrimeClock, IPrimeTime
- Inheritance
-
PrimeTestClock
- Implements
- Inherited Members
Remarks
SetInstant(Instant), SetLocalTime(LocalDateTime), and Noda "now" members share semantics with the BCL partial documented on IPrimeTestClock. Use a NodaTime.DateTimeZone constructor when tests need explicit zone rules (for example daylight saving).
Constructors
- PrimeTestClock()
Initializes a new instance with virtual time set to the current system instant.
- PrimeTestClock(Instant)
Initializes a new instance with the specified initial instant and system default zone.
- PrimeTestClock(Instant, DateTimeZone)
Initializes a new instance with the specified initial instant and time zone.
Properties
- LocalNowDate
Gets the current local date (no time component) in the system default zone.
- LocalNowDateOnly
Gets the current local date as DateOnly.
- LocalNowDateTime
Gets the current local date and time as a DateTime.
- LocalNowDateTimeOffset
Gets the current local date and time as a DateTimeOffset.
- LocalNowInstant
Gets the current local date and time (NodaTime.Instant) in the system default time zone as a NodaTime.LocalDateTime (no time zone information).
- LocalNowTime
Gets the current local time of day (no date component) in the system default zone.
- LocalNowTimeOnly
Gets the current local time-of-day as TimeOnly.
- LocalScheduleDateTimeZone
Gets the Noda NodaTime.DateTimeZone used for local calendar-day and local wall-clock time when resolving LocalZonedNowInstant and local day-time timer registration (the same zone object that backs LocalScheduleTimeZone when that property exposes a wrapped BCL zone).
- LocalScheduleTimeZone
Gets the time zone used to resolve the local calendar date and local wall-clock time for local day-time timer registration and for LocalZonedNowInstant.
- LocalZonedNowInstant
Gets the current date and time (NodaTime.Instant) in the system default time zone as a NodaTime.ZonedDateTime.
- NowInstant
Gets the current instant on the global timeline (UTC).
- UtcNowDate
Gets the current UTC date (no time component).
- UtcNowDateOnly
Gets the current UTC date as DateOnly.
- UtcNowDateTime
Gets the current UTC date and time as a DateTime.
- UtcNowDateTimeOffset
Gets the current UTC date and time as a DateTimeOffset.
- UtcNowInstant
Gets the current date and time (NodaTime.Instant) in UTC as a NodaTime.ZonedDateTime.
- UtcNowTime
Gets the current UTC time of day (no date component).
- UtcNowTimeOnly
Gets the current UTC time-of-day as TimeOnly.
- UtcZonedNowInstant
Gets the current date and time (NodaTime.Instant) in UTC as a NodaTime.ZonedDateTime. Equivalent to UtcNowInstant for symmetry with LocalZonedNowInstant.
Methods
- Advance(Duration)
Advances the clock's virtual time by the specified duration. Pending delays (Sleep, DelayAsync) that are due by the new time complete, time-based cancellation tokens that expire by the new time are cancelled, and any interval or day-time timers that are due are invoked.
- Advance(TimeSpan)
Advances virtual time forward by marching to each earliest due instant up to the new horizon, then dispatching delays, time expiries, and timers at each step.
- OnSchedulingMutatedWhileGateHeld()
Notifies the automatic runner that scheduling changed while KZDev.PrimeTime.Testing.PrimeTestTimeBase.Gate is held.
- RegisterAsyncTimeOfDay(LocalTimeOfDay, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a local time-of-day timer with an asynchronous callback that receives timer context and cancellation token. Other
RegisterAsyncTimeOfDayoverloads for LocalTimeOfDay are provided as extension methods.
- RegisterAsyncTimeOfDay(UtcTimeOfDay, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a UTC time-of-day timer with an asynchronous callback that receives timer context and cancellation token. Other
RegisterAsyncTimeOfDayoverloads for UtcTimeOfDay are provided as extension methods.
- RegisterAsyncTimeOfDay(LocalTime, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a time-of-day timer with an asynchronous callback that receives context and cancellation token. Other NodaTime.LocalTime
RegisterAsyncTimeOfDayoverloads are extension methods.
- RegisterAsyncTimer(Duration, Duration, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, IntervalTimerOptions?)
Registers an interval timer with an initial delay, a repeat interval, and an asynchronous callback that receives timer context and cancellation token. Other NodaTime.Duration-based
RegisterAsyncTimeroverloads are extension methods.
- RegisterAsyncTimer(TimeSpan, TimeSpan, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, IntervalTimerOptions?)
Registers an interval timer with an initial delay, a repeat interval, and an asynchronous callback that receives timer context and cancellation token. Other
RegisterAsyncTimeroverloads are provided as extension methods.
- RegisterTimeOfDay(LocalTimeOfDay, Action<ClockTimerCallbackContext>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a local time-of-day timer with a synchronous callback that receives timer context and optional state. Other
RegisterTimeOfDayoverloads for LocalTimeOfDay are provided as extension methods.
- RegisterTimeOfDay(UtcTimeOfDay, Action<ClockTimerCallbackContext>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a UTC time-of-day timer with a synchronous callback that receives timer context and optional state. Other
RegisterTimeOfDayoverloads for UtcTimeOfDay are provided as extension methods.
- RegisterTimeOfDay(LocalTime, Action<ClockTimerCallbackContext>, CancellationToken, object?, DayTimeTimerOptions?)
Registers a time-of-day timer with a callback that receives context and state. Other NodaTime.LocalTime
RegisterTimeOfDayoverloads are extension methods.
- RegisterTimer(Duration, Duration, Action<ClockTimerCallbackContext>, CancellationToken, object?, IntervalTimerOptions?)
Registers an interval timer with an initial delay, a repeat interval, and a synchronous callback that receives timer context. Other NodaTime.Duration-based
RegisterTimeroverloads are extension methods.
- RegisterTimer(TimeSpan, TimeSpan, Action<ClockTimerCallbackContext>, CancellationToken, object?, IntervalTimerOptions?)
Registers an interval timer with an initial delay, a repeat interval, and a synchronous callback that receives timer context. Other
RegisterTimeroverloads are provided as extension methods.
- RunFor(Duration)
Starts a bounded automatic run that advances virtual time by
durationat a 1:1 real-time pace (one second of virtual time per real second), then stops when that virtual elapsed time is reached.
- RunFor(Duration, Duration)
Starts a bounded automatic run that advances virtual time by
durationatperSecondRate(virtual time per one real second), then stops when that virtual elapsed time is reached.
- RunFor(TimeSpan)
Starts a bounded automatic run that advances virtual time by
durationat a 1:1 real-time pace (one second of virtual time per real second), then stops when that virtual elapsed time is reached.
- RunFor(TimeSpan, TimeSpan)
Starts a bounded automatic run that advances virtual time by
durationatperSecondRate(virtual time per one real second), then stops when that virtual elapsed time is reached.
- SetInstant(Instant)
Sets the current UTC instant, using forward marching when
instantis strictly after the current virtual time.
- SetLocalTime(LocalDateTime)
Sets virtual time from a local wall-clock value in the clock's zone, using forward marching when the resolved instant is strictly after the current virtual time.
- SetTime(DateTimeOffset)
Sets the current UTC time of the clock to the specified value. When the clock is not running, this is the time returned by UtcNowDateTimeOffset and related members.
- Start(Duration?)
Starts the deadline-driven automatic runner at the given virtual-time-per-real-second rate.
- Start(TimeSpan?)
Starts a background runner that advances virtual time toward the next delay, time-expiry, timer due instant, or virtual-minute ClockEvents heartbeat, scaled by the run rate.
- Stop()
Stops the automatic runner and clears the monotonic run anchor.
Events
- ClockEvents
Occurs when the clock publishes a discriminated lifecycle or virtual-time event.