question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifying (`.add()`, `.subtract()`, etc.) a dayjs instance created in UTC corrupts it

See original GitHub issue

Setting 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:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BePo65commented, Oct 28, 2022

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 😃

1reaction
BePo65commented, Oct 17, 2022

I could reproduce the issue; working on a solution / pr.

Read more comments on GitHub >

github_iconTop 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 >
Subtract
Returns a cloned Day.js object with a specified amount of time subtracted.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found