-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Incorrect endOf & startOf when daylight saving in effect #1262
Comments
Here's a mimatch comparison of day.js an moment showing different results which I believe is related to daylight savings. https://runkit.com/lucasrcosta/5feca83aea7c09001b879b3a is related to |
Hello, BTW, it seems there are other issue tickets that affect the |
Strangely, the offset appears to be correct when using dayjs("2021-03-25T22:00:00.000Z").tz("Europe/Prague").endOf("month").format()
// 2021-03-31T23:59:59+02:00 So one workaround is new Date(dayjs("2021-03-25T22:00:00.000Z").tz("Europe/Prague").endOf("month").format()).toISOString()
// 2021-03-31T21:59:59.000Z I just wrote a simple wrapper function function toISOString(dateTime: string | Date | dayjs.Dayjs) {
return new Date(dayjs(dateTime).format()).toISOString();
} I am using version 1.10.6, so maybe this is new behavior. In any case, part of the issue appears to be that Here's a more comprehensive example for The issue seems to be that import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
dayjs.extend(utc);
dayjs.extend(timezone);
const march10 = "2021-03-10T22:00:00.000Z";
const march20 = "2021-03-20T22:00:00.000Z";
const november3 = "2021-11-03T22:00:00.000Z";
const november20 = "2021-11-20T22:00:00.000Z";
// ===
// startOf month from 03-10
// ===
console.log("startOf month from 03-10");
console.log(dayjs(march10).tz("America/Los_Angeles").startOf("month").toISOString());
// 2021-03-01T07:00:00.000Z
console.log(dayjs(march10).tz("America/Los_Angeles").startOf("month").format());
// 2021-03-01T00:00:00-08:00
console.log(new Date(dayjs(march10).tz("America/Los_Angeles").startOf("month").format()).toISOString());
// 2021-03-01T08:00:00.000Z
// ===
// endOf month from 03-10
// ===
console.log("endOf month from 03-10");
console.log(dayjs(march10).tz("America/Los_Angeles").endOf("month").toISOString());
// 2021-04-01T05:59:59.999Z
console.log(dayjs(march10).tz("America/Los_Angeles").endOf("month").format());
// 2021-03-31T23:59:59-07:00
console.log(new Date(dayjs(march10).tz("America/Los_Angeles").endOf("month").format()).toISOString());
// 2021-04-01T06:59:59.000Z
// ===
// startOf month from 03-20
// ===
console.log("startOf month from 03-20");
console.log(dayjs(march20).tz("America/Los_Angeles").startOf("month").toISOString());
// 2021-03-01T07:00:00.000Z
console.log(dayjs(march20).tz("America/Los_Angeles").startOf("month").format());
// 2021-03-01T00:00:00-08:00
console.log(new Date(dayjs(march20).tz("America/Los_Angeles").startOf("month").format()).toISOString());
// 2021-03-01T08:00:00.000Z
// ===
// endOf month from 03-20
// ===
console.log("endOf month from 03-20");
console.log(dayjs(march20).tz("America/Los_Angeles").endOf("month").toISOString());
// 2021-04-01T05:59:59.999Z
console.log(dayjs(march20).tz("America/Los_Angeles").endOf("month").format());
// 2021-03-31T23:59:59-07:00
console.log(new Date(dayjs(march20).tz("America/Los_Angeles").endOf("month").format()).toISOString());
// 2021-04-01T06:59:59.000Z
// ===
// startOf month from 11-03
// ===
console.log("startOf from 11-03");
console.log(dayjs(november3).tz("America/Los_Angeles").startOf("month").toISOString());
// 2021-11-01T06:00:00.000Z
console.log(dayjs(november3).tz("America/Los_Angeles").startOf("month").format());
// 2021-11-01T00:00:00-07:00
console.log(new Date(dayjs(november3).tz("America/Los_Angeles").startOf("month").format()).toISOString());
// 2021-11-01T07:00:00.000Z
// ===
// endOf month from 11-03
// ===
console.log("endOf from 11-03");
console.log(dayjs(november3).tz("America/Los_Angeles").endOf("month").toISOString());
// 2021-12-01T06:59:59.999Z
console.log(dayjs(november3).tz("America/Los_Angeles").endOf("month").format());
// 2021-11-30T23:59:59-08:00
console.log(new Date(dayjs(november3).tz("America/Los_Angeles").endOf("month").format()).toISOString());
// 2021-12-01T07:59:59.000Z
// ===
// startOf month from 11-20
// ===
console.log("startOf from 11-20");
console.log(dayjs(november20).tz("America/Los_Angeles").startOf("month").toISOString());
// 2021-11-01T06:00:00.000Z
console.log(dayjs(november20).tz("America/Los_Angeles").startOf("month").format());
// 2021-11-01T00:00:00-07:00
console.log(new Date(dayjs(november20).tz("America/Los_Angeles").startOf("month").format()).toISOString());
// 2021-11-01T07:00:00.000Z
// ===
// endOf month from 11-20
// ===
console.log("endOf from 11-20");
console.log(dayjs(november20).tz("America/Los_Angeles").endOf("month").toISOString());
// 2021-12-01T06:59:59.999Z
console.log(dayjs(november20).tz("America/Los_Angeles").endOf("month").format());
// 2021-11-30T23:59:59-08:00
console.log(new Date(dayjs(november20).tz("America/Los_Angeles").endOf("month").format()).toISOString());
// 2021-12-01T07:59:59.000Z |
I believe it causes by the error of valueOf function. |
I confirm the issue persists. Also, the workaround with |
Issue is still there in 1.11.13 For example instead of: You use: |
Describe the bug
startOf and endOf functions does not work correctly when timezone plugin in use and daylight saving in effect.
This seems to be regression from 1.9.6 (worked in 1.9.6 and does not work in 1.9.7).
This is output from 1.9.7:
This is output from 1.9.6:
Expected behavior
Momentjs produces correct result:
Related
I believe the error is caused by this pull request: #1229
Not sure but this is maybe related to this bug: #1260
The text was updated successfully, but these errors were encountered: