Old dates have weird minute offsets in utc
See original GitHub issueDescribe 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:
- Created a year ago
- Comments:14 (5 by maintainers)
Top 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 >
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

One of the problems of offset is the handling of seconds (see issue #1905).
Using
utcOffsetwith 1 parameter, sets the utcOffset of a given dayjs object.Using
utcOffsetwith 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.