NodaTimeProvider

Namespace: SnowBank.Threading · class

Implements: TimeProvider, IClock

A single source of time exposed through BOTH the BCL TimeProvider facade (timestamps, timers, delays, timeouts) and the NodaTime IClock facade (Instants)

Remarks

The two facades always read the SAME underlying provider, so code stamping Instants via IClock and code scheduling via TimeProvider can never diverge - the classic bug where a test advances a fake provider (timers fire at virtual T+30s) while documents keep being stamped with the real wall clock.

Production registers System (wrapping System); a timing-sensitive test wraps a FakeTimeProvider and advances it: timers, timeouts AND Instants move together.

Constructors

NodaTimeProvider

NodaTimeProvider(TimeProvider inner)

Wraps an existing provider (the system provider in production, a fake advanceable provider in tests)

Properties

Inner

TimeProvider Inner { get; }

The single underlying source of time that both facades read

LocalTimeZone

TimeZoneInfo LocalTimeZone { get; }

TimestampFrequency

long TimestampFrequency { get; }

Methods

CreateTimer

ITimer CreateTimer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period)

GetCurrentInstant

Instant GetCurrentInstant()

GetTimestamp

long GetTimestamp()

GetUtcNow

DateTimeOffset GetUtcNow()

ToString

string ToString()

Fields

System

static readonly NodaTimeProvider System

The real system clock, exposed through both facades