date-fns-tz: utcToZonedTime returns next day when time matches offset
Hello, first of thanks for your work, dates are such a pain, I don’t even want to think about working on a date library 😫
Anyway, I’ve come across this issue with date-fns-tz, I’ve tried to make a reduced issue here: https://codepen.io/atomcorp/pen/gObqoyX
In short the following returns a Date object for the 24th not 23rd
utcToZonedTime(
new Date('Thu Jan 23 2020 05:00:00 GMT+0000 (Greenwich Mean Time)'),
'America/New_York' // -5 hours
);
It seems to happen when the inputted time matches the offset of the timezone. So if you move the time of the inputted date an hour back or forward, so it’s different to the timezone offset, both utcToZonedTime and the native method return the same.
Like I said times are weird, so maybe this is expected behaviour!? 🤷♂️
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 17 (6 by maintainers)
Commits related to this issue
- fix : utcToZonedTime returns next day when time matches offset fix #38 — committed to hyyan/date-fns-tz by hyyan 4 years ago
Thanks again all. Please check out
1.0.10and let me know if there are still any issues.Thank you all. This was a tricky one to solve. Thank you @hyyan for making a PR. I will review and merge over the weekend.
Ok, I’ve looked into this more. The issue is restricted to Chrome Canary (I’m on 81.0.4039.0). It’s specifically related to do with Intl.DateTimeFormat which is used in tzTokenizeDate.
Working example here
I haven’t found any Chrome issues about this, I don’t know whether this is a Chrome bug or a change in behavior that is upcoming. But 24:00:00 is an invalid time surely, so probably just a bug that hopeufly gets squished before it gets full released.