Skip to content Skip to sidebar Skip to footer

Javascript Intl Api Gives Different Results In Chrome

I am using JavaScript Intl API to detect the user's timezone in the browser: Intl.DateTimeFormat().resolvedOptions().timeZone While this API looks stable, I don't know what to do

Solution 1:

Chrome, like many others, gets its time zone information through ICU, which in turn sources from CLDR, which in part sources from IANA.

There is a subtle difference between IANA and CLDR with regard to canonicalization.

  • IANA treats the preferred form of the time zone identifier as canonical. If the preferred form changes, they make the new one primary (a Zone entry) and move the old one to an alias (a Link entry).

  • CLDR treates the first form of the time zone identifier as canonical. That is, the first time it appeared in CLDR, it is locked in forever. If a new form ever appears, it is added as an alias in the /common/bcp47/timezone.xml file.

Taking your case of Indianapolis:

  • IANA Zone entry (reference here)

    Zone    America/Indiana/Indianapolis    ...
    
  • IANA Link entry (reference here)

    Link    America/Indiana/Indianapolis    America/Indianapolis
    
  • In CLDR, the primary zone is listed first in the "aliases" attribute, followed by other aliases. (reference here)

    <typename="usind"description="Indianapolis, United States"alias="America/Indianapolis America/Fort_Wayne America/Indiana/Indianapolis US/East-Indiana"/>

The same thing can be found with Asia/Calcutta vs. Asia/Kolkata and several other examples.

Additionally, be aware that the Windows time zone mappings also source from CLDR, in the /common/supplemental/windowsZones.xml file. You'll notice there that US Eastern Standard Time is mapped to America/Indianapolis. So the difference between browsers depends very much on which canonicalization rules are followed.

In the end, it doesn't really matter which alias is used. They point at the same data.

Also worth pointing out, that particular Windows zone should only be selected if you care about historical time changes in Indiana. If you are just in the US Eastern time zone, you should set your system to "Eastern Standard Time", rather than "US Eastern Standard Time". (Yes, those IDs are confusing...)

Solution 2:

zone.tab is incomplete. Some time zones are represented as symbolic links:

$ find /usr/share/zoneinfo/America -name Indianapolis -exec file {} \;
/usr/share/zoneinfo/America/Indiana/Indianapolis: symbolic link to ../Indianapolis
/usr/share/zoneinfo/America/Indianapolis: timezone data, version 2, 7 gmt time flags, 7 std time flags, no leap seconds, 99 transition times, 7 abbreviation chars

Post a Comment for "Javascript Intl Api Gives Different Results In Chrome"