commenthol / date-holidays-parser

parser for worldwide holidays
ISC License
46 stars 22 forks source link

Replace moment dependency with a modern library #55

Open stefanvanherwijnen opened 1 year ago

stefanvanherwijnen commented 1 year ago

Moment is now considered a legacy project: https://www.npmjs.com/package/moment

There have been multiple PR's already: https://github.com/commenthol/date-holidays-parser/pull/53 https://github.com/commenthol/date-holidays-parser/pull/48 https://github.com/commenthol/date-holidays-parser/pull/2

It would be nice if @commenthol could clarify which newer library should best be used.

commenthol commented 1 year ago

In reality this project relies heavily on moment-timezone. The important data here is the reliability on the timezone which uses data from IANA time zone database that is maintained and up to date.

Unfortunately moment-js is required for using moment-timezone.

I understand the current moment project status and the need to move to some other library instead.

Nonetheless I fear that this will cause major drawbacks with the accuracy. The IANA Database is usually maintained by the underlying OS. In case of nodeJS the timezone database seams to be queried by the included ICU library.

From https://stackoverflow.com/questions/55477931/where-does-node-js-get-the-timezone-data-from

Generally, it should be noted ICU data archive is updated less frequently than the IANA timezone data. Therefore, you may have to deal with outdated timezone information in Node.js even if you always install the latest Node.js LTS release. This is indicated by the tz properties value 2018e which indicates a fairly old version of timezone data. The current IANA timezone data is dated from March 2019

IMO Luxon or date-fns will suffer from this design decision.

If used in the browser, things tend to be worse.

From https://support.google.com/chrome/thread/139901584/does-chrome-use-iana-database-for-timezone-information?hl=en

Chrome on Windows uses the date and time settings built-in to Windows.

With moment-timezone it can be accomplished that the timezone-data is accurate amongst all clients and platforms. This is something I don't want to trade with tickets stating that this and that date is wrong, but in reality timezone data on that client is outdated.

I am following the Temporal.ZonedDateTime Proposal which I would consider as a replacement for moment-timezone. But again we'd need to see where to get really up to date timezone data amongst all clients using this library.

Maybe you are aware of a JS-project which uses IANA timezone data and offers this in a "tiny" library.

stefanvanherwijnen commented 1 year ago

Thanks for your thorough explanation. This should clear things up for everyone (including me) wondering why we are stuck with moment.

Unfortunately I am not aware of any alternatives myself. date-holidays works great, but I am getting errors when using it in the browser due to moment not supporting ESM. And since moment won't be updated, the best solution seems to be to find a suitable replacement for it.