KZDev.PrimeTime — usage guide (NodaTime superset)
Package ID: KZDev.PrimeTime
Namespace: KZDev.PrimeTime
This guide describes the full PrimeTime package: everything in the SystemClock subset plus NodaTime-centric members on IPrimeClock and NodaTime timer overloads. NodaTime is a required dependency of this package.
When to use this package
- You already use NodaTime for instants, zones, and calendars.
- You want
Instant,ZonedDateTime,LocalTime, andDurationon the same clock abstraction as your BCL projections. - You want
Duration-based interval registration andLocalTime-based time-of-day registration onIPrimeClock(see API reference).
This package includes all the BCL/TimeProvider functionality from SystemClock plus NodaTime extensions. If you prefer minimal dependencies and don't need NodaTime types, use KZDev.SystemClock.PrimeTime.
Install
dotnet add package KZDev.PrimeTime
This pulls in NodaTime transitively. Target frameworks shipped by this repository: net10.0, net8.0, netstandard2.0.
Dependency injection
using KZDev.PrimeTime;
using Microsoft.Extensions.DependencyInjection;
IServiceCollection services = new ServiceCollection();
services.AddPrimeClock();
AddPrimeClock registers:
| Service | Default implementation | Notes |
|---|---|---|
NodaTime.IClock |
SystemClock.Instance |
Skipped if you already registered IClock. |
IPrimeClock |
PrimeClock singleton |
Uses the registered NodaTime IClock. |
IPrimeTime |
same instance as IPrimeClock |
Resolved via factory. |
NodaTime-first “now”
IPrimeClock in this assembly extends the shared contract with properties such as:
NowInstant,UtcNowInstant,LocalZonedNowInstantLocalNowTime,UtcNowTime,LocalNowDate,UtcNowDate
Use these when the rest of your domain speaks NodaTime. BCL projections remain available from the shared contract where applicable for your target framework.
Timers
- Interval: use
TimeSpanoverloads orDurationoverloads (superset-only). - Time of day: use
LocalTime/LocalDateoverloads on supported targets, withDayTimeTimerOptionsfor DST. See Timers, daylight saving, and testing.
Virtual time tests
PrimeTestClock supports NodaTime-centric construction (for example an initial Instant and DateTimeZone). That combination is especially useful for deterministic DST tests. See the testing assembly reference for exact constructors and IPrimeTestClock members.
Runnable examples
Self-contained snippets for this stack live under PrimeTime (NodaTime) examples. Each page reproduces the relevant code in the documentation site so you do not need to navigate the repository to read it. Highlights:
- DI registration — what
AddPrimeClockregisters (including the NodaTimeIClock) and how to resolve it. - "Now" surfaces — NodaTime-first projections (
NowInstant,LocalZonedNowInstant,LocalNowTime,LocalNowDate). - Persistence and conversions — schedule-zone projection for persisted
Instantvalues; time-of-day and delay conversions (see also testing). - Sleep, delay, and cancellation —
Sleep,DelayAsync, and time-based cancellation tokens (Duration-typed). - Interval timers and time-of-day & DST — production wall-clock scheduling.
- Testing counterparts: Interval (testing), Time-of-day & DST (testing), and the cross-track DI replacement and test-clock control pages.
Related documentation
- Choosing a package
- Persistence and time conversions
- KZDev.SystemClock.PrimeTime
- Shared concepts
- Production API: KZDev.PrimeTime · Testing API: KZDev.PrimeTime.Testing