Modifying (`.add()`, `.subtract()`, etc.) a dayjs instance created in UTC corrupts it
See original GitHub issueSetting timezone explicitly
dayjs.tz(0, 'UTC').format()
'1970-01-01T00:00:00Z' - Result
'1970-01-01T00:00:00Z' - Expected
dayjs.tz(0, 'UTC').add(0,'minutes').format()
'1969-12-31T23:00:00Z' - Result
'1970-01-01T00:00:00Z' - Expected
dayjs.tz(0, 'UTC').add(1,'minutes').format()
'1969-12-31T23:01:00Z' - Result
'1970-01-01T00:01:00Z' - Expected
Setting default timezone
The above results are identical, when omitting 'UTC' and setting UTC as default:
dayjs.tz.setDefault('UTC')
dayjs.tz(0).format()
'1970-01-01T00:00:00Z' - Result
'1970-01-01T00:00:00Z' - Expected
dayjs.tz(0).add(0,'minutes').format()
'1969-12-31T23:00:00Z' - Result
'1970-01-01T00:00:00Z' - Expected
dayjs.tz(0).add(1,'minutes').format()
'1969-12-31T23:01:00Z' - Result
'1970-01-01T00:01:00Z' - Expected
Information
- Day.js Version 1.11.5
- OS: Mac
- Browser: Chrome
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
subtract() can't change current Day.js object #844 - GitHub
Describe the bug the api subtract() can't change current Day.js object. utcOffset() too. Expected behavior those api can change current ...
Read more >Add
Returns a cloned Day.js object with a specified amount of time added. const a = dayjs const b = dayjs().add(7, 'day') // a...
Read more >UTC
Returns a Dayjs object in UTC mode. Use UTC time .utc(). Returns a cloned Dayjs object with a flag to use UTC time....
Read more >ObjectSupport
utc , dayjs().set , dayjs().add , dayjs().subtract APIs to support object argument. var objectSupport = ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes I tried every combination and found that the problem is the utc time zone (even as gmt e.a.) I am working on it for the last 2 weeks, but i could not yet solve all combinations. At the moment I just have to fix the .tz(‘UTC’) variant.
Please be patient as it will take me for sure a few more days; but I won’t surrender 😃
I could reproduce the issue; working on a solution / pr.