Converting to a GMT TZ when only Updating Offset Produces Wrong Value
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When creating a dayjs object in a timezone that has a non-zero offset (e.g. Australia/Hobart) and converting to a zero offset timezone (e.g. "utc") _**whilst only converting the offset**_ produces the wrong values when formatting the timezone.
For example consider the following code:
```
const one = dayjs.tz("2020-01-01T15:00:00", "Australia/Hobart");
const two = one.tz("utc", true);
console.log(two.hour() === one.hour()) // this is false!
console.log(two.format()) // "2020-01-01T04:00:00Z" not 15:00!
```
We would expect the boolean expression on the third line to be true, because the API says that the local time should be preserved, but it is actually false!
As far as I can tell, this behaviour only occurs when converting _**to**_ a GMT-0 timezone.
It doesn't matter which specific timezone is being used for either `one` or `two`, just that `one` is non-zero GMT and `two` is GMT-0.
If converting to a non-zero GMT timezone, the behaviour works as expected.
**Expected behavior**
In the code snippet above, the console should print "true" on line 3.
**Information**
- Day.js Version 1.11.7
- OS: Ubuntu 22
- Browser: Firefox 109.0
- Time zone: GMT+11 (Australia/Hobart)
Contributor guide
Research direction
Start by running the provided Australia/Hobart to UTC example against Day.js 1.11.7 and trace the timezone conversion path used by the second .tz call. Done means preserving the local hour when the offset-only conversion targets UTC, while retaining the expected formatted output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- internationalization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100