
Installing the package (pre-authenticated): Install-Package NodaTime.Testing -Source NuGet (Package Manager Console) Installing the package (search all configured feeds): Install-Package NodaTime.Testing Installing the package (HTTP Basic authentication): Install-Package NodaTime.Testing -Source
Nodatime iclock install#
Installing the package (pre-authenticated): nuget install NodaTime.Testing -Source
Nodatime iclock code#
Offset values, but in many tests it's simplest just to give the number of hours, as in the code above.)Ĭreating a time zone with no transitions at all is simple via (nuget.exe) Installing the package (HTTP Basic authentication): nuget install NodaTime.Testing -Source (With both SingleTransitionDateTimeZone and MultiTransitionDateTimeZone, the offsets can also be specified with The offsets and ID provided to the constructor are used for the beginning of time up until the first specified transition,Īt which point the offsets and ID provided with that transition are used until the next transition, etc. Var zone = new MultiTransitionDateTimeZone.Builder(2, 1, "X") For example: var transition1 = new Instant(0L) The standard and saving offsets forĮach part of the time zone can be specified separately. The zone intervals within the time zone do not have aĭaylight saving aspect they just have the specified standard offsets.įor more complex scenarios, MultiTransitionDateTimeZoneĪllows you to create a time zone from a collection of transitions, using a builder type. The ID of the zone can also be specified,Īnd the names of the early/late zone intervals are based on the ID. This will create a zone which moves from UTC+3 to UTC+5 at the transition point. Var zone = new SingleTransitionDateTimeZone(transition, 3, 5) var transition = new Instant(100000L) // Or use Instant.FromUtc With a single transition between different offsets, and is suitable for most test purposes. SingleTransitionDateTimeZone represents a time zone Time zonesįor time zones themselves, there are two fake implementations. The production environment should usually beĬonfigured with one of the providers in DateTimeZoneProviders.

If you need to set other properties on the builder, the zones have to be specified through the Zones property: var source = new FakeDateTimeZoneSource.Builder Where CreateZone is just a method returning a DateTimeZone. If you only need to specify the time zones, it's simplest to just use a collection initializer with the builder, like this: var source = new FakeDateTimeZoneSource.Builder
Nodatime iclock windows#
Is constructed (via a builder) with any DateTimeZone instances you want, and you can also specify custom Windows TimeZoneInfo ID mappings. We do have a test double: FakeDateTimeZoneSource. IDateTimeZoneSource - to retrieve time zones under the hood, and there.There are currently no test doubles for this interface, but usually

Time zone providers and sourcesįor code which is sensitive to time zone fetching, an IDateTimeZoneProvider canīe injected. Zone, possibly with one of the extension methods in.

The ZonedClock class helps with this, but doesn't need to be faked out: theĮxpectation is that you'll only need to fake out the IClock, then wrap that in a ZonedClock for the appropriate Often you may want to repeatedly access the current time or date in a specific time zone. The productionĮnvironment should normally inject the singleton SystemClock instance which simply The FakeClock canīe set to any given instant, advanced manually, or set to advance a given amount each time it's accessed. Inherently bound to any time zone or calendar). Which simply provides "the current date and time" (as an Instant, given that the concept of "now" isn't The most obvious dependency is a clock - an implementation of NodaTime.IClock, (If it's not, please file a bug report.) Clocks

No particular support for any specific dependency injection framework, but should be easy to configure with any While you can use Noda Time without dependency injection, it will make your code harder to test. The purpose of the assembly is to provideĮasy-to-use test doubles which can be used instead of the real implementations. Small, but it will no doubt grow - and it will make your life much easier. This page is not about how Noda Time itself is tested - it's about how you to test codeįirstly, get hold of the NodaTime.Testing assembly.
