Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to include linked time zones #54

Open
caseyjhol opened this issue Oct 20, 2022 · 1 comment
Open

Option to include linked time zones #54

caseyjhol opened this issue Oct 20, 2022 · 1 comment

Comments

@caseyjhol
Copy link

caseyjhol commented Oct 20, 2022

The "America/New_York" time zone has a "US/Eastern" link.

However, when using:

new MomentTimezoneDataPlugin({
    matchCountries: ['US'],
}),

or

new MomentTimezoneDataPlugin({
    matchZones: ['America/New_York'],
}),

"US/Eastern" does not show up in moment.tz.names(). I see there is some existing code that appears to handle links, but it apparently doesn't do what I was expecting. Some links are included, it seems, but others are not.

It would be great if there was an option to include linked time zones as well. I'm working around this for now by including /^US\// in matchZones, but it's not a perfect solution.

  • moment v2.29.4
  • moment-timezone v0.5.38
  • moment-timezone-data-webpack-plugin v1.5.1
@gilmoreorless
Copy link
Owner

I agree this is a slightly confusing scenario. (I even had to go and double-check my own code just to make sure I properly understood what was happening.)

First, here's why the plugin (currently) doesn't include US/Eastern:

  1. The matchZones option will include only zones that match the provided value(s). If a zone is defined in moment-timezone as a link, then the zone it points to is also included. So asking for US/Eastern will also include America/New_York, but not the other way around. This was done because some zones have many, many links (e.g. America/Puerto_Rico has 20 links pointing to it).
  2. The matchCountries option chooses which zones are included based on the countries data provided by moment-timezone. For US, this is 29 zones.
    1. Those entries originally come from the zone.tab and zone1970.tab files in the IANA time zone database. US/Eastern doesn't appear in any of those lists, mainly because it's using an old, long-deprecated naming format that the tzdb maintainers would like people to move away from.
    2. As with matchZones, there is some link handling here, but only if the links are found in that primary countries list.

I'll have a think about adding an option to include all links that point to the defined zones. It would probably be useful for other use cases too. In the meantime I think adding the extra ^US/ matcher like you have is the best workaround.

I've also created #55 to add more documentation about how zones are included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants