Issue #73 resolved

Use new internationalization API when possible

Matt Johnson
created an issue

Some time zone improvements are starting making their way into JavaScript via the newly proposed ECMAScript Internationalization API. I learned of this after stumbling upon some stuff in Google Chrome, which has started to implement pieces of it. See this post on StackOverflow.

The interesting part for jsTimeZoneDetect is that the browser can now return the actual IANA time zone string. According to the spec, this is supposed to happen with this code:


But Chrome apparently hasn't implemented that yet. However, you can still get it in Chrome, using this implementation:


On my machine, this returns America/Phoenix.

I propose that we try to detect either function. If they exist, then we should use them directly and ignore the rest of the detection logic.

Eventually, when all of the browsers support this natively, jsTimeZoneDetect can be thought of as a shim for supporting older browsers.

Comments (9)

  1. Jon Nylander repo owner

    Great work Matt!

    The weird thing is, it gives me "America/Anchorage" for Alaska, but only "CET" for Europe/Stockholm.

    CET is perhaps an IANA time zone, but still, seems like the granularity is not fully in place yet.

  2. Brendan White

    Intl.DateTimeFormat().resolvedOptions().timeZone correctly gives Australia/Adelaide for me in Chrome 38 on my Mac, if that's useful to know.

    I haven't worked out how it to run in Safari or Firefox yet though.

  3. Log in to comment