tz() wrong when timezone is the same
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
Converting to the same timezone sometimes returns the wrong offset:
```js
dayjs.tz('2021-01-01', 'Europe/Madrid').format()
// "2021-01-01T00:00:00+01:00" - OK
dayjs.tz('2021-01-01', 'Europe/Madrid').tz('Europe/Madrid').format()
// "2021-01-01T00:00:00+02:00" - INCORRECT; offset should be same as above
```
Weirdly, the issue does not occur when moving the date by 6 months
```js
dayjs.tz('2021-06-01', 'Europe/Madrid').format()
// "2021-06-01T00:00:00+02:00" - OK
dayjs.tz('2021-06-01', 'Europe/Madrid').tz('Europe/Madrid').format()
// "2021-06-01T00:00:00+02:00" - OK
```
**Expected behavior**
Converting a value that's already `Europe/Madrid` to `Europe/Madrid` should return the same value.
**Information**
- Day.js Version: v1.10.4
- OS: Windows 10 20H2
- Browser: Chrome 90
- Time zone: GMT+02:00 DST (Romance Daylight Time)
Contributor guide
Research direction
Reproduce the two Europe/Madrid examples from the issue, comparing the direct conversion with the repeated .tz('Europe/Madrid') conversion for January and June. Trace the timezone conversion entry point used by the tz() API, then verify that converting to the same timezone preserves the original value and offset.
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
- Clearly specified
- Newbie friendliness
- 35/100