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
startOf/endOf misbehave with timezone plugin enabled #1573
Comments
has no issue in my case const dayjs = require("dayjs")
const utc = require("dayjs/plugin/utc");
const timezone = require("dayjs/plugin/timezone");
dayjs.extend(utc);
dayjs.extend(timezone);
console.log(dayjs.tz("2020-11-02T00:00:00", "Europe/Berlin").startOf("month").toDate()); // 2020-10-31T23:00:00.000Z Day.js Version: 1.10.6 |
@imwh0im Indeed. The default system TZ is part of this problem.
|
@flashspys Should the two result values be the same? I'm asking because I don't know the script in the |
@imwh0im it's probably the code from your comment. |
Hello, just stumbled upon the same bug and it doesn't seem related to the system's timezone. Here's the context:
Example: const input = dayjs.tz('2021-06-18 00:00', 'Europe/Paris');
console.log(input.endOf('day').format('YYYY-MM-DDTHH:mm:ssZ[Z]')); // 2021-06-18T23:59:59+02:00Z - correct
console.log(input.endOf('day').tz('UTC').format('YYYY-MM-DDTHH:mm:ssZ[Z]')); // 2021-06-18T20:59:59+00:00Z - invalid Instead of using endOf(), doing this "by hand" actually works (but requires first ensuring hour input is 00:00:00): const input = dayjs.tz('2021-06-18 00:00', 'Europe/Paris');
console.log(input.add(1, 'day').subtract(1, 'second').format('YYYY-MM-DDTHH:mm:ssZ[Z]')); // 2021-06-18T23:59:59+02:00Z - correct
console.log(input.add(1, 'day').subtract(1, 'second').tz('UTC').format('YYYY-MM-DDTHH:mm:ssZ[Z]')); // 2021-06-18T21:59:59+00:00Z - valid |
Describe the bug
startOf/endOf returns the wrong value with timezone plugin enabled. The information about the timezone gets lost
Expected behavior
The expected output to code above is imho
2020-10-31T23:00:00.000Z
, which relates to 2020-11-01T00:00:00 in Europe/BerlinWorkaround
We looked into the code and found the
.toDate()
parameter. The code works as expected when calling.toDate("s")
.Information
The text was updated successfully, but these errors were encountered: