Re:Dates and Times in JavaScript – A New API for Dates from ...
by mattwad on Thursday July 09, 2020 @01:50PM
(#23782921)
I've been using date-fns on the backend. It's great; so long as you don't have to deal with timezones, because the functions only accept and return Date objects, which don't support internal timezone. The other day I needed to get the hour of day based on a user's timezone, though. And had to resort to moment-timezone because NO i dont want to have to handle the math on my own.
[ Parent
| on HN ]
Re:Dates and Times in JavaScript – A New API for Dates from ...
by kcorbitt on Thursday July 09, 2020 @01:56PM
(#23782988)
Check out https://www.npmjs.com/package/date-fns-tz. The API is much less intuitive than the `date-fns` one because javascript Date objects don't store their timezone, but I've used it in a real project and it's workable once you grok the mental model.
Re:Dates and Times in JavaScript – A New API for Dates from ...
by sratner on Thursday July 09, 2020 @03:32PM
(#23784109)
Personally, I prefer Luxon's timezone handling. I get the appeal of not providing custom classes, but _actually changing the underlying timestamp_ to adjust for timezone has always caused nothing but trouble for me. It becomes an all-or-nothing system (you must use `date-fns-tz` to manipulate the dates) with nothing to actually enforce that.