`utcOffset()` returns incorrect result after adding or subtracting hours to a value.
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
```js
const dayjs = require('dayjs'); dayjs.extend(require('dayjs/plugin/utc')); dayjs.extend(require('dayjs/plugin/timezone'));
const t1 = dayjs.tz('2022-03-13T00:00:00', 'America/Montreal');
const t2 = dayjs.tz('2022-03-13T04:00:00', 'America/Montreal');
console.log(t1.utcOffset()); // -300, which is correct
console.log(t2.utcOffset()); // -240, which is correct, because we crossed a DST boundary
const t3 = t1.add(3, 'hours');
console.log(t3.valueOf() === t2.valueOf()); // True - midnight plus three hours is 4am, because of DST.
console.log(t3.utcOffset()); // -300, which is incorrect - should be -240.
```
**Expected behavior**
When moving a date between DST periods, we expect the utcOffset to be updated (this is how moment.js works).
**Information**
- Day.js Version: 1.10.8
- OS: MacOS
- Browser: Node 16.14.0
- Time zone: America/Montreal
Contributor guide
Research direction
Start by running the reported Node.js reproduction with the utc and timezone plugins for America/Montreal, then trace the utcOffset behavior used by add(). Add a regression test covering the DST boundary; done means the added value reports the same offset as the equivalent parsed time (-240).
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