Subtract with Timezone bug
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
I experienced subtract error when I use timezones, an example:
```
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js'
import timezone from 'dayjs/plugin/timezone.js'
dayjs.extend(utc);
dayjs.extend(timezone);
const dt1=dayjs().tz("Atlantic/Reykjavik")
console.log(dt1.format("YYYY-MM-DD HH:mm"))
const dt2=dt1.subtract(1,"day")
console.log(dt2.format("YYYY-MM-DD HH:mm"))
```
Result:
```
2023-08-24 00:38
2023-08-22 22:38
```
Version: "dayjs": "^1.11.7",
Contributor guide
Research direction
Start by running the provided reproduction with the utc and timezone plugin entry points, then inspect how subtract handles a timezone-aware Day.js value. Done means the one-day subtraction preserves the intended local time and produces the expected date for Atlantic/Reykjavik, with a regression test for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100