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

utcToZonedTime() incorrect while toDate() correct around daylight saving time #31

Closed
soetji opened this issue Nov 7, 2019 · 7 comments

Comments

@soetji
Copy link

soetji commented Nov 7, 2019

This year for "America/New_York" the daylight saving ended on Nov 3, 02:00 where it turned back 01:00. My browser is on a local "America/New_York" system.

toDate() gets this correctly but not utcToZonedTime(). utcToZonedTime() adds an hour even before 02:00.

toDate('2019-11-03T03:00:00.000Z', { timeZone: 'America/New_York' })
// Sat Nov 02 2019 23:00:00 GMT-0400 (Eastern Daylight Time)

utcToZonedTime('2019-11-03T03:00:00.000Z', 'America/New_York')
// Sun Nov 03 2019 00:00:00 GMT-0400 (Eastern Daylight Time)


toDate('2019-11-03T04:00:00.000Z', { timeZone: 'America/New_York' })
// Sun Nov 03 2019 00:00:00 GMT-0400 (Eastern Daylight Time)

utcToZonedTime('2019-11-03T04:00:00.000Z', 'America/New_York')
// Sun Nov 03 2019 01:00:00 GMT-0400 (Eastern Daylight Time)


toDate('2019-11-03T05:00:00.000Z', { timeZone: 'America/New_York' })
// Sun Nov 03 2019 01:00:00 GMT-0400 (Eastern Daylight Time)

utcToZonedTime('2019-11-03T05:00:00.000Z', 'America/New_York')
// Sun Nov 03 2019 01:00:00 GMT-0500 (Eastern Standard Time)


toDate('2019-11-03T06:00:00.000Z', { timeZone: 'America/New_York' })
// Sun Nov 03 2019 01:00:00 GMT-0500 (Eastern Standard Time)

utcToZonedTime('2019-11-03T06:00:00.000Z', 'America/New_York')
// Sun Nov 03 2019 01:00:00 GMT-0500 (Eastern Standard Time)


toDate('2019-11-03T07:00:00.000Z', { timeZone: 'America/New_York' })
// Sun Nov 03 2019 02:00:00 GMT-0500 (Eastern Standard Time)

utcToZonedTime('2019-11-03T07:00:00.000Z', 'America/New_York')
// Sun Nov 03 2019 02:00:00 GMT-0500 (Eastern Standard Time)
@soetji
Copy link
Author

soetji commented Nov 7, 2019

It looks like the bug in utcToZonedTime goes with the system timezone. It works correctly on the GMT timezone system.

// Correct on a GMT timezone system
utcToZonedTime('2019-11-03T03:00:00.000Z', 'America/New_York')
// Sat Nov 02 2019 23:00:00 GMT-0400 (Eastern Daylight Time)
utcToZonedTime('2019-11-03T03:00:00.000Z', 'America/New_York').getTimezoneOffset()
// 0

// Incorrect on a America/New_York timezone system
utcToZonedTime('2019-11-03T03:00:00.000Z', 'America/New_York')
// Sun Nov 03 2019 00:00:00 GMT-0400 (Eastern Daylight Time)
utcToZonedTime('2019-11-03T03:00:00.000Z', 'America/New_York').getTimezoneOffset()
// 240

@marnusw
Copy link
Owner

marnusw commented Nov 8, 2019

That's good to know! I'm on GMT so would probably not have managed to reproduce this.

@constgen
Copy link

constgen commented Jan 10, 2020

This is a real problem. utcToZonedTime() gives a different result when you use the system timeZone explicitly and pass the date near the DST switching hour

let timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone
let date = new Date() // choose the date +1h right after switching to Standart Time from Summer Time
let zonedDate = utcToZonedTime(value, timeZone);
let time = format(zonedDate, 'p', { timeZone })
console.log(time) // As the time zone is system, the time should match to `date` time, but it is not.

Actually this formatting produces the same hour 3 times during moving from Summer Time to Standart Time

@altodoro
Copy link

Seems like the similar issue here: utcToZonedTime() adds an extra day to the returned date when converting date with time in range 23:00 - 23:59

utcToZonedTime('2020-02-26T23:15:00Z', 'Europe/Berlin');
// expected -> Fri Feb 27 2020 00:15:00 GMT+0200 (Eastern European Standard Time)
// actual   -> Fri Feb 28 2020 00:15:00 GMT+0200 (Eastern European Standard Time)

@marnusw
Copy link
Owner

marnusw commented Feb 11, 2020

@altodoro I think the issue you are reporting is #38 / #43 rather than related to issues around the DST change. Please check whether version 1.0.10 solves your issue.

@altodoro
Copy link

@altodoro I think the issue you are reporting is #38 / #43 rather than related to issues around the DST change. Please check whether version 1.0.10 solves your issue.

yep, you're right. Thanks for the update!

make-github-pseudonymous-again added a commit to infoderm/healthone that referenced this issue Jun 15, 2020
Does not seem to be working at the moment in some edge cases of daylight
saving time. See the issues of date-fns-tz, for instance:
  - marnusw/date-fns-tz#31
  - marnusw/date-fns-tz#44
  - marnusw/date-fns-tz#70
@marnusw
Copy link
Owner

marnusw commented Oct 5, 2020

This might be fixed in version 1.0.11 which will be available soon. Please reopen if not.

@marnusw marnusw closed this as completed Oct 5, 2020
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

Successfully merging a pull request may close this issue.

4 participants