Add / Subtract functions changing timezone
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**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)
Contributor guide
Assessment
This issue has not been assessed yet.