iamkun / iamkun/dayjs

Add / Subtract functions changing timezone

Open
#1,689 0 comments 4 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.