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

Add / Subtract functions changing timezone #1689

Open
squirrl opened this issue Nov 9, 2021 · 0 comments
Open

Add / Subtract functions changing timezone #1689

squirrl opened this issue Nov 9, 2021 · 0 comments

Comments

@squirrl
Copy link

squirrl commented Nov 9, 2021

Describe the bug
I have the following code:

let startOfDayUnmodified = dayjs().startOf('day');
// $d: Tue Nov 09 2021 00:00:00 GMT-0700 (Mountain Standard Time)

let startOfDayWithAdd = dayjs().startOf('day').add(-7, 'days');
// $d: Tue Nov 02 2021 00:00:00 GMT-0600 (Mountain Daylight Time)

Edited after futher investigation:

When adding or subtracting time across the DST transition, the outputted dayjs has the timezone for the output time. This isn't technically wrong, the underlying time since epoch is correct, but it feels unexpected. I would expect the specified input timezone to match the output, regardless of the DST boundary.

Expected behavior
Adding or subtracting from a dayjs should yield the result in the input timezone:

let startOfDayUnmodified = dayjs().startOf('day');
// $d: Tue Nov 09 2021 00:00:00 GMT-0700 (Mountain Standard Time)

let startOfDayWithAdd = dayjs().startOf('day').add(-7, 'days');
// $d: Tue Nov 02 2021 01:00:00 GMT-0700 (Mountain Standard Time)

(Note, that I realize this may be subjective. I'm happy that I found the underlying object to still have the correct time since epoch, but my preference would be to change the behavior to use a consistent timezone.)

Information

  • Day.js Version 1.10.7
  • OS: Windows
  • Browser: Chrome 95, firefox
  • Time zone: GMT-07:00 MST (Mountain Standard Time)
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