0

I recently started using NodaTime and I must say it is a fantastic piece of work.

However, just to test that I am doing things right, I took IANA timezone names from here and printed UTC Offsets for each using NodaTime.

/* string[] ALL_ZONE_NAMES = list of zone names */
foreach(var timezone in ALL_ZONE_NAMES)
        {
            var ob = DateTimeZoneProviders.Tzdb[timezone];
            Console.WriteLine($"{timezone} --> {ob.GetUtcOffset(new Instant())}");
        }

Now, for a particular timezone say Pacific/Apia, offset was printed as -11,

enter image description here

but when I tried same on Chrome browser (console) from the momentJS, I got +14

moment.tz(new Date().toISOString(), "Pacific/Apia").format()
"2020-12-10T01:33:13+14:00"

Am I missing something ?

6
  • Probably. On the one hand, both libraries use the IANA Timezone database so if one of them uses an older database, the offsets may be different. What does the database itself contain for those timezones? Dec 9, 2020 at 11:47
  • 1
    On the other hand though, -11 is +13. Which makes +14 look suspiciously like DST. Which is indeed currently in effect Dec 9, 2020 at 11:48
  • @PanagiotisKanavos What does the database itself contain for those timezones? which database ? You mean DateTimeZoneProviders.Tzdb ? How do I check that ?
    – SimpleGuy
    Dec 9, 2020 at 11:51
  • @PanagiotisKanavos And to add, I am using latest Noda Time version
    – SimpleGuy
    Dec 9, 2020 at 11:55
  • The IANA timezone database is one database compiled by IANA and used by Linux, all airlines, just about everyone except Windows itself. Some libraries use the OS's version, some package a version in their binaries. Since Windows doesn't use tzdb, NodaTime has to package a copy, which may be out of date. That's not the problem here though. In any case, you can add an updated version Dec 9, 2020 at 11:55

1 Answer 1

2

In the Noda Time code, you're using new Instant(), which refers to the Unix epoch (1970-01-01T00:00:00Z). In the Javascript code you're using new Date() which uses the current date and time.

Change your Noda Time code to use ob.GetUtcOffset(SystemClock.Instance.GetCurrentInstant()) to make it behave like the Javascript code.

Note that you can get a full list of transitions with offsets for all time zones in terms of Noda Time results at https://nodatime.org/tzvalidate/generate - and you can specify a zone and/or IANA database version as well, e.g. https://nodatime.org/tzvalidate/generate?version=2020d&zone=Pacific/Apia to just show the Pacific/Apia results using the 2020d database.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.