Calling `.tz("UTC", true)` after `.tz("UTC")` on the same object seems to mutate it
- 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 and changing its timezone to any zone with 0 offset (UTC, in this example, for simplicity), then calling `.tz("UTC", true)` on the same object, it appears as if it has some kind of mutation.
Using `isSame` to compare the object with a copy of itself that was declared before calling `.tz("UTC", true)` returns `false`, although in the console both objects seem to have equal values.
[Reproduction on Codesandbox](https://codesandbox.io/p/sandbox/dayjs-0-offset-issue-nfpwwq?file=%2Fsrc%2Findex.mjs%3A27%2C26)
As stated, this happens with all zones with 0 offset, so, for instance, replacing 'UTC' with 'Africa/Abidjan' in the code yields the same result.
In general, everything utc related seems to be kinda weird right now, as there are some other shenanigans that I have encountered in our actual project but can't find a way to properly reproduce them in an isolated environment.
**Expected behavior**
`isSame` should return `true` due to immutability.
**Information**
- Day.js Version: v1.11.13
- OS: macOS Monterey 12.5
- Browser: Chrome 127
- Time zone: GMT-06:00, also happens when using the browser's console to emulate a timezone with a positive offset, such as GMT+01:00.
Contributor guide
Research direction
Start by running the linked CodeSandbox reproduction in src/index.mjs and compare the results of the two .tz calls with isSame. Trace the timezone behavior for zero-offset zones such as UTC and Africa/Abidjan; done means the original object remains immutable and isSame returns true.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100