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

Operations across Daylight Saving/Standard Time producing incorrect results #1828

Closed
tptshoe opened this issue Mar 11, 2022 · 1 comment
Closed

Comments

@tptshoe
Copy link

tptshoe commented Mar 11, 2022

Describe the bug
On a machine that does not have daylight saving time active (ie, if on the US east coast on March 11, 2022), converting a dayjs object with a date that has Daylight Saving time active (ie: March 15, 2022) to a JS Date object results in the time being incorrect

const testTime = dayjs('03-15-2022 09:30:00').tz('America/New_York');
console.log('DayJS', testTime.format()); <- output: 'DayJS 2022-03-15T09:30:00-04:00'
console.log('JS Date', testTime.toDate()); <- output: 'JS Date Tue Mar 15 2022 08:30:00 GMT-0400 (Eastern Daylight Time)'

In this example the JS Date has a time one hour earlier than expected

NOTE: Setting system date to 3/15/2022 solves the issue, but for obvious reasons that's not really a fix.

Expected behavior
The time should be correct

Information

  • Day.js Version: ^1.10.4
  • OS: MacOS/Windows
  • Browser: Chrome 99.0.4844.51 (Official Build) (x86_64)
  • Time zone: America/New_York

WORKAROUND:
You can get the correct result if you convert the Dayjs object to a string, ie: new Date(testTime.format('ddd MMM DD YYYY HH:mm:ss Z')) <- this produces the correct result

@tptshoe
Copy link
Author

tptshoe commented Mar 12, 2022

This is a duplicate of issue #1819 - Sorry, didn't spot that earlier.

@tptshoe tptshoe closed this as completed Mar 12, 2022
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

1 participant