Result is one hour off when subtracting days over DST transition
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
The subtraction of days gives wrong result when DST transition takes place between the start and end date.
Check the following example:
```
// Running node with TZ='UTC'
dayjs.tz("2021-04-12 00:00:00", "Europe/Athens")
.subtract(16, "days")
.toISOString()
// result is "2021-03-26T21:00:00.000Z"
// Correct would be "2021-03-26T22:00:00.000Z"
```
A test project to reproduce the bug can be found at https://github.com/faberchri/dayjs_bugs
The bug does not occur if node runs with `TZ='Europe/Zurich'`.
**Expected behavior**
The correct offset to UTC is applied at shifted date. I.e. not 3 hours (as in DST) but only 2 hours.
This is actually what luxon does, see the test app.
**Information**
- Day.js Version 1.10.7
- OS: macOS 11.6.1
- node v16.13.0
- Time zone: I'm in "Europe/Zurich", but **test app runs with TZ='UTC'**
Contributor guide
Research direction
Start with the reproduction described in the issue and the linked dayjs_bugs test project, running Node with TZ='UTC' and the Europe/Athens example. Trace the timezone-aware subtract and ISO conversion behavior, then verify that subtracting 16 days produces the expected 2021-03-26T22:00:00.000Z result across the DST transition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100