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
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:
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.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.
See more on this question at Stackoverflow