New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Old dates have weird minute offsets in utc #1996
Comments
My timezone is Europe/Vilnius. This is curious. code: const moment = require("moment");
const dayjs = require("dayjs");
const utc = require("dayjs/plugin/utc");
dayjs.extend(utc);
const f = "YYYY-MM-DD HH:mm:ss Z";
// loop same day every 11 years for the past 200 years
for (let i = 2022; i > 1800; i -= 11) {
const dayjsDate = dayjs(`12/31/${i}`).utc(true).format(f);
const momentDate = moment.utc(`12/31/${i}`).format(f).toString();
console.log(`${dayjsDate} === ${momentDate}`);
} result: 2022-12-31 00:00:00 +00:00 === 2022-12-31 00:00:00 +00:00
2011-12-31 00:00:00 +00:00 === 2011-12-31 00:00:00 +00:00
2000-12-31 00:00:00 +00:00 === 2000-12-31 00:00:00 +00:00
1989-12-31 00:00:00 +00:00 === 1989-12-31 00:00:00 +00:00
1978-12-31 00:00:00 +00:00 === 1978-12-31 00:00:00 +00:00
1967-12-31 00:00:00 +00:00 === 1967-12-31 00:00:00 +00:00
1956-12-31 00:00:00 +00:00 === 1956-12-31 00:00:00 +00:00
1945-12-31 00:00:00 +00:00 === 1945-12-31 00:00:00 +00:00
1934-12-31 00:00:00 +00:00 === 1934-12-31 00:00:00 +00:00
1923-12-31 00:00:00 +00:00 === 1923-12-31 00:00:00 +00:00
1912-12-31 00:06:00 +00:00 === 1912-12-31 00:00:00 +00:00
1901-12-31 00:06:00 +00:00 === 1901-12-31 00:00:00 +00:00
1890-12-31 00:06:00 +00:00 === 1890-12-31 00:00:00 +00:00
1879-12-31 00:03:44 +00:00 === 1879-12-31 00:00:00 +00:00
1868-12-31 00:03:44 +00:00 === 1868-12-31 00:00:00 +00:00
1857-12-31 00:03:44 +00:00 === 1857-12-31 00:00:00 +00:00
1846-12-31 00:03:44 +00:00 === 1846-12-31 00:00:00 +00:00
1835-12-31 00:03:44 +00:00 === 1835-12-31 00:00:00 +00:00
1824-12-31 00:03:44 +00:00 === 1824-12-31 00:00:00 +00:00
1813-12-31 00:03:44 +00:00 === 1813-12-31 00:00:00 +00:00
1802-12-31 00:03:44 +00:00 === 1802-12-31 00:00:00 +00:00 the results differ very much depending on the location of the machine. Shouldn't Edit: formatted the output |
Indeed, depends on localtion, but I'm getting the same result for both libs, again small demo and my results:
|
Seems to be a bug with |
This is not a bug, but the correct implementation of time zones. So for example for CET the definition of the time zone ("UTC offset") changed several times over the years, as can be seen in the timeanddate web page). The time zone definitions can be found on the iana Time Zone Database. This database is implemented for example in the Internationalization API of javascript, the basis for time zones in dayjs. |
@BePo65 interesting. This causes a few issues for my needs though.
are there any other ways to set utc mode without this "feature"? currently I use moment and it works as I expect it to. |
Hi, sorry, I'm far from timezones, but why does |
Using Using 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: I'm working on a pr for this issue; give me a few days. |
in the meantime: how about using
instead of
In a quick test, this solves the point on my machine (I believe 😄 ). Nevertheless I will try to fix the utcOffset issue, as I am working on the dayjs 2.0 utc plugin and this could / should be fixed there too. |
Thank you for your investigation, indeed, in console:
|
With such format it returns the same |
I did some more research and it seems the issue is not related to dayjs, here is small demo with date: Ouput:
Still can't understand how did it working as UTC offset in 1912 is +02:30... Where 17 seconds are from? @BePo65, thank you for your links above, all is correct, the timezone shift in 1912 was +02:30:17 My misunderstood between |
One of the problems of offset is the handling of seconds (see issue #1905). |
After more tests and investigation here my current interpretation of the original problem of this issue: The code from @irgipaulius compares
Both results look the same at the first view, but things get complicated, if the timezone offset contains seconds. Using I created an example for 'Europe/Kiev":
So if you would use the same function for moment and dayjs, the results would be s´the same in both cases - even moment(string).utc(true) shows the 'mysterious' seconds 😄 Besides of this, there remains the problem of dayjs with seconds in the timezone offset (see also issue #1905). I created a PR (#2016) for this, hoping that it helps solve the points with historical dates. |
Example for offset not full or halve hours is '1879-12-31' for timezone 'Europe/Berlin', where utcOffset is '00:53'. Solves issue iamkun#1996.
Describe the bug
Take this as an example:
Expected behavior
Actual behavior
Information
The text was updated successfully, but these errors were encountered: