How would I get a list containing only and all canonical IANA time zone ids in javascript?
While I fully intend to support all IANA time zone ids in my application, when users select a timezone, I want the options to only contain currently canonical zones.
Preferably, I would like a way to achieve this using javascript apis (Intl/Temporal - even if they are not widely available yet), but a solution using luxon, dayjs, or other packages would also be quite welcome.
Failed approaches
- Intl.supportedValuesOf('timeZone')
This returns a list of primary time zone identifiers, which
uniquely identify the time zone [and] usually refer to a geographic area anchored by a city...
and as such are a concept distinct from canonical ids, as described in this note:
Note that the attribution of primary identifiers preserves the country code: for example, the IANA database records Atlantic/Reykjavik as a link for Africa/Abidjan, but because they correspond to different countries (Iceland and Côte d'Ivoire, respectively), they are treated as distinct primary identifiers.
- The tzdb package.
This returns too narrow of a list. It's rules for grouping are
- if the time zones are in the same country
- if the [DST and non-DST] offsets are the same
which, for example, means that America/Indiana/Indianapolis is grouped under America/New_York, despite being a distinct canonical id.
- Don't try to get canonical ids, and instead settle for Temporal's list of primary time zone identifiers
I am open to being convinced that the list returned by Intl.supportedValuesOf('timeZone') is what I want. However, it does not currently seem that way to me. Why?
It seems this complication has arisen because Temporal invented a new concept, primary time zone identifiers, which is distinct from canonical time zone ids. I understand that sometimes a link is scoped to a country different than the id to which it resolves (as in the example I quoted). However, if they are intended to be treated differently and both be current options, why would IANA have created the link relationship? Temporal is very subtly diverging from IANA in their terminology and behavior, and is setting up all but those who carefully read the documentation to be confused (and I can tell you from my experience over the last few weeks that llms are not up to speed on the distinction and have not helped in guiding me on this).
Creating a new standard also has x-framework implications - e.g. in my case our api is not javascript so its lists will not match the front end if the front end is not following IANA standards.
Atlantic/Reykjavikis not a canonical tz id, however, the js api regards it as "primary"backwardtzdb file, data.iana.org/time-zones/tzdb/backward, says this: "# This file provides links from old or merged timezone names to current ones." Based off that note, it seems odd for Temporal/Intl to be consideringAtlantic/Reykjavikand several others as primary tz ids when they are only listed in this file.