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.

Old dates have weird minute offsets in utc

See original GitHub issue

Describe the bug Take this as an example:

// loop same day every 11 years for the past 200 years
for (let i = 2022; i > 1800; i -= 11) {
  console.log(dayjs(`12/31/${i}`).utc(true).toDate());
}

Expected behavior

2022-12-31T00:00:00.000Z
2011-12-31T00:00:00.000Z
2000-12-31T00:00:00.000Z
1989-12-31T00:00:00.000Z
1978-12-31T00:00:00.000Z
1967-12-31T00:00:00.000Z
1956-12-31T00:00:00.000Z
1945-12-31T00:00:00.000Z
1934-12-31T00:00:00.000Z
1923-12-31T00:00:00.000Z
1912-12-31T00:00:00.000Z
1901-12-31T00:00:00.000Z
1890-12-31T00:00:00.000Z
1879-12-31T00:00:00.000Z
1868-12-31T00:00:00.000Z
1857-12-31T00:00:00.000Z
1846-12-31T00:00:00.000Z
1835-12-31T00:00:00.000Z
1824-12-31T00:00:00.000Z
1813-12-31T00:00:00.000Z
1802-12-31T00:00:00.000Z

Actual behavior

2022-12-31T00:00:00.000Z
2011-12-31T00:00:00.000Z
2000-12-31T00:00:00.000Z
1989-12-31T00:00:00.000Z
1978-12-31T00:00:00.000Z
1967-12-31T00:00:00.000Z
1956-12-31T00:00:00.000Z
1945-12-31T00:00:00.000Z
1934-12-31T00:00:00.000Z
1923-12-31T00:00:00.000Z
1912-12-31T00:06:00.000Z   /// what???
1901-12-31T00:06:00.000Z
1890-12-31T00:06:00.000Z
1879-12-31T00:03:44.000Z   /// huh??!
1868-12-31T00:03:44.000Z
1857-12-31T00:03:44.000Z
1846-12-31T00:03:44.000Z
1835-12-31T00:03:44.000Z
1824-12-31T00:03:44.000Z
1813-12-31T00:03:44.000Z
1802-12-31T00:03:44.000Z   /// it goes on like this until 100 AC

Information

  • Day.js Version ^1.11.4
  • OS: MacOs Big Sur 11.6
  • NodeJS
  • Time zone: [e.g. GMT+03:00 DST]

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
BePo65commented, Jul 25, 2022

One of the problems of offset is the handling of seconds (see issue #1905).

1reaction
BePo65commented, Jul 25, 2022

why does .utcOffset(0,true) has another results

Using utcOffset with 1 parameter, sets the utcOffset of a given dayjs object.

Using utcOffset with 2 parameters, sets the utcOffset of a given dayjs object while keeping the time value of that object. And therefore using .utcOffset(0, true) gets other values (this fragment avoids the critical branch in the code).

Regarding that point, the documentation is not really complete (at least I didn’t find it in the documentation, only in the source code). @Bykiev : perhaps you want to make a PR for the documentation on the corresponding project?

Back to time zones / utcOffset:
sorry that it took me so long to understand the issue. If I get it right, your point is not about correct definition of timezones. The point is that .utcOffset(true) does not keep the local time. And that is really an error in dayjs.

I’m working on a pr for this issue; give me a few days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting weird time value when formatting older dates #5148
Parsing date/time string with timezone offset ( YYYY-MM-DDTHH:mm:ssZZ format) and then formatting it using local timezone produces (seemingly) ...
Read more >
What is going on with this historical Timezone Offset UTC+ ...
From the lone search result I would then get to this SO answer Parsing historical UTC date times gives an odd time zone...
Read more >
Unusual Time Zones - WorldTimeServer.com
Not every time zone is based on an hour offset. There are 30 and 45 minute offsets in addition to the normal hour...
Read more >
Time zone offset of future dates? - Request Feedback - Elm
This means the Zone you get from this function will act weird if (1) an application stays open across a Daylight Saving Time...
Read more >
Half Hour and 45-Minute Time Zones - Time and Date
While most time zones differ from Coordinated Universal Time (UTC) by a number of full hours, some time zones have 30-minute or 45-minute...
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