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

Is there an alternative to moment-timezone with bundled IANA TZ DB? #1103

Closed
driver-by opened this issue Apr 22, 2024 · 3 comments
Closed

Is there an alternative to moment-timezone with bundled IANA TZ DB? #1103

driver-by opened this issue Apr 22, 2024 · 3 comments

Comments

@driver-by
Copy link

All alternatives rely on Intl browser API, but browsers don't update TZ DB reliably. If it's important to have correct times in different timezones in your application, the only way is moment + moment-timezone now. And these projects being in maintenance mode makes me sad 😢
Anything I miss?

I see that js-joda provides some IANA DB (taken from moment-timezone?), but the package is not updated often. I could contribute with tz updates myself there, but it also depends on maintainers' possibility to apply PRs.

Just one example of the Chromium being really behind with these updates:
January 23, 2024 - news about Kazakhstan being moved to single timezone starting March 1, 2024
February 01, 2024 - IANA DB updated to 2024a including this timezone change
February 03, 2024 - moment-timezone updated to 2024a version
February 29, 2024 - the issue in Chromium about lack of Kazakhstan TZ change
March 8, 2024 - marked as fixed in Chromium tracker
And then it takes some time to get updates on the client side.

Despite it's being a pretty quick fix, the update was pretty late. Moreover, it looks like the process is not automated, and is done manually after an issue is being raised.

@gilmoreorless
Copy link
Member

I'm not sure about other date/time libraries that still bundle their own tzdb data. However, if you want full control over the dataset, you could try a hybrid approach: Use one of the many libraries that rely on Intl, but add a custom polyfill such as https://formatjs.io/docs/polyfills/intl-datetimeformat#adding-iana-timezone-database
(Note: I haven't tried this approach myself, so I can't verify its effectiveness.)

@Schnark
Copy link

Schnark commented Jul 5, 2024

I didn't try to use it, but there is also https://github.com/spiritit/timezonecomplete + https://github.com/rogierschouten/tzdata-generate, and given that the release with 2024a was published on Feb 1, this library seems to be very well managed.

@driver-by
Copy link
Author

@gilmoreorless , @Schnark thank you for your advices.
I choose the polyfill and looks wonderful. Basically, I can use any library I want and add the TZ bundle on top

For somebody who can use this approach, just install
npm i @formatjs/intl-datetimeformat
and in your code:

import '@formatjs/intl-datetimeformat/polyfill-force';
import '@formatjs/intl-datetimeformat/locale-data/en';
import '@formatjs/intl-datetimeformat/add-all-tz';

With polyfill-force you force overriding browser's TZ data, even if they have that.

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

3 participants