Wrong result when manipulating timezone date
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.8k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When I use dates in a timezone and add a duration the result time looks bad
```
const dayjs = require('dayjs');
const timezone = require('dayjs/plugin/timezone');
const utc = require('dayjs/plugin/utc');
dayjs.extend(utc);
dayjs.extend(timezone);
// Accra timezone is in UTC + 0 so UTC time and Accra time should be same
const startDate = dayjs.utc('2022-04-05 12:00:00').tz('Africa/Accra')
console.log(startDate.format('YYYY-MM-DD HH:mm:ss')) // Result => '2022-04-05 12:00:00'
const endDate = startDate.add(1, 'h')
console.log(endDate.format('YYYY-MM-DD HH:mm:ss')) // Result => '2022-04-05 11:00:00'
```
**Expected behavior**
As I add an hour I expect to get '2022-04-05 13:00:00' and not '2022-04-05 11:00:00'
It seems to be related to the browser timezone. I am personally in Central European Summer Time (GMT+2).
But if I change the timezone of Chrome with devTools for 'Africa/Accra'. The problem doesn't seem to happen again
Obviously when I look at the open issues I am not the only one to have problems with the timezone, is there anything planned to fix this? Thank you in advance :)
**Information**
- Day.js Version 1.10.7
- OS: Ubuntu 21.10
- Browser chrome 99
- Time zone: Central European Summer Time (GMT+2)
Contributor guide
Research direction
Start by reproducing the provided Day.js UTC and timezone plugin example in Chrome with different browser time zones, then compare the displayed result with the expected 13:00:00. Done means adding one hour preserves the expected Accra wall-clock time regardless of the browser timezone and the regression is covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100