NodaTime update manual tz db

there is a section "Using a NodaZoneData file" on how to include and load the tz data from a NodaZoneData file.

the code section show the following

    IDateTimeZoneProvider provider;
    // Or use Assembly.GetManifestResourceStream for an embedded file
    using (var stream = File.OpenRead("tzdb-2013h.nzd"))
    {
        var source = TzdbDateTimeZoneSource.FromStream(stream);
        provider = new DateTimeZoneCache(source);
    }
    Console.WriteLine(provider.SourceVersionId);

How do you set the created provider to the NodaTime library in order to use it as a default? NodaTime release do not follow the tz data release. Will this be changed in the future? Is there another way to get a updated NodaTime lib with tzdb data updated as a nuget?

Thanks

Jon Skeet
people
quotationmark

How do you set the created provider to the NodaTime library in order to use it as a default?

Very few things in Noda Time use any provider as the default. (Similarly we don't use the system time zone by default, and try to avoid implicitly using the current culture, other than for compatibility.) Looking at the current 2.0 source code, the only references are in ClockExtensions and DateTimeZoneProviders.Serialization (which is used by XML and binary serialization, and which can be set in application code).

If you want to have your own application-wide default, I suggest you create your own class with a static property exposing an IDateTimeZoneProvider, or maybe a singleton. Refer to that anywhere you'd otherwise refer to DateTimeZoneProviders.Tzdb.

In terms of keeping things up to date:

  • A new nzd file is posted on the Noda Time web site very soon after each new release. You can detect that by fetching http://nodatime.org/tzdb/latest.txt which contains a URL to the latest file.
  • There are options we're considering around how to release nuget packages:
    • Have a nuget package just containing the data (and a tiny amount of "bootstrapping" code probably), and removing the embedded data from NodaTime.dll
    • Have a nuget package containing all the TZDB-specific code, and removing the embedded data from NodaTime.dll
    • Just change our release practices so that a new NodaTime nuget package can be pushed at the same time as the new file

None of the options is simple to implement, and there's a lot of other Noda Time work to do (reimplementing the web site with docfx, scheduling benchmarks using BenchmarkDotNet and exposing that data on the web site, and of course finishing the 2.0 code base). We'll get to it, but don't hold your breath for it being Real Soon Now.

people

See more on this question at Stackoverflow