System Clock examples
Self-contained snippets for the KZDev.SystemClock.PrimeTime stack (BCL types, TimeProvider, TimeSpan, DateTimeOffset). Each page shows code copied directly from the in-repo example projects:
- Production demos live in
Source/Dev/Production/KZDev.SystemClock.PrimeTime.Examples/. - Test demos live in
Source/Dev/Testing/KZDev.SystemClock.PrimeTime.Testing.Examples/and use xUnit with AwesomeAssertions.
Production
- Interval timers — register sync and async interval callbacks on
IPrimeClock. - Time-of-day and DST — register local wall-clock callbacks, plus environment-aware skipped/ambiguous handling and the clock's
LocalScheduleTimeZone. - DI registration — what
AddPrimeClockregisters and how to resolve the abstractions. - "Now" surfaces — the
LocalNow*andUtcNow*projections this stack exposes. - Persistence and conversions (production) — UTC
DateTimeOffset→ schedule zone;DateOnly/TimeOnlyextraction and recombination. - Sleep, delay, and cancellation —
Sleep,DelayAsync, and time-based cancellation tokens.
Testing (virtual time)
- Interval timers (testing) — drive interval timers under
PrimeTestClockwithAdvance. - Time-of-day and DST (testing) — environment-aware DST probes and stable virtual-clock advancement.
- Persistence and conversions (testing) — schedule-zone
DateTimeOffsetprojection andDateOnly/TimeOnlyround-trips.
Cross-track testing examples
The following pages cover patterns shared by both stacks; both are presented side-by-side:
Related
- Concepts: Persistence and time conversions · Timers, daylight saving, and testing
- Usage guide: KZDev.SystemClock.PrimeTime
- API: Production · Testing