You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TZ date: 2024-03-31 00:00:00, UTC date: 2024-03-30T23:00:00.000Z
TZ date: 2024-03-31 01:00:00, UTC date: 2024-03-31T00:00:00.000Z
TZ date: 2024-03-31 03:00:00, UTC date: 2024-03-31T02:00:00.000Z <--- wrong
TZ date: 2024-03-31 04:00:00, UTC date: 2024-03-31T03:00:00.000Z
The third line is wrong. DST happens at 02:00 local time and therefore local time jumps from 1:59 to 3. This is correct. However, UTC time should not skip an extra hour as well.
Expected behavior
I write a similar snippet using Java and ZonedDateTime, and it appears to print the correct values (not the same date formats):
TZ date: 2024-03-31T00:00+01:00[Europe/Oslo], UTC date: 30 Mar 2024 23:00:00 GMT
TZ date: 2024-03-31T01:00+01:00[Europe/Oslo], UTC date: 31 Mar 2024 00:00:00 GMT
TZ date: 2024-03-31T03:00+02:00[Europe/Oslo], UTC date: 31 Mar 2024 01:00:00 GMT
TZ date: 2024-03-31T04:00+02:00[Europe/Oslo], UTC date: 31 Mar 2024 02:00:00 GMT
Also, doing it the other way around by adding hours to the Date objects and creating a new Dayjs object from that everytime works (append the following code inside the printDates function):
let currentDate = startOfDayWithDST.toDate();
for(let i = 0; i < 4; i++) {
currentTime = dayjs.tz(currentDate, "Europe/Oslo");
this.printDate(currentTime);
currentDate.setHours(currentDate.getHours() + 1)
}
TZ Date: 2024-03-31 00:00:00, UTC date: 2024-03-30T23:00:00.000Z
TZ Date: 2024-03-31 01:00:00, UTC date: 2024-03-31T00:00:00.000Z
TZ Date: 2024-03-31 03:00:00, UTC date: 2024-03-31T01:00:00.000Z
TZ Date: 2024-03-31 04:00:00, UTC date: 2024-03-31T02:00:00.000Z
Information
Day.js Version: v1.11.10
OS: Any (mostly tested on Ubuntu and Mac)
Browser: Chrome (probably others)
Time zone: Europe/Oslo
The text was updated successfully, but these errors were encountered:
** Description of the problem **
Running the current typescript code:
printDates() {
var timeAfterDaylightSavings = new Date(2024, 2, 31, 18, 0, 0, 0);
var startOfDayWithDST = dayjs.tz(timeAfterDaylightSavings, "Europe/Oslo").startOf('day');
var currentTime = startOfDayWithDST;
for(let i = 0; i < 4; i++) {
this.printDate(currentTime);
currentTime = currentTime.add(1, 'hour');
}
}
printDate(d: dayjs.Dayjs) {
return console.log("Date: " + d.format('YYYY-MM-DD HH:mm:ss') + ", UTC date: " + d.toDate().toISOString());
}
It prints the following:
TZ date: 2024-03-31 00:00:00, UTC date: 2024-03-30T23:00:00.000Z
TZ date: 2024-03-31 01:00:00, UTC date: 2024-03-31T00:00:00.000Z
TZ date: 2024-03-31 03:00:00, UTC date: 2024-03-31T02:00:00.000Z <--- wrong
TZ date: 2024-03-31 04:00:00, UTC date: 2024-03-31T03:00:00.000Z
The third line is wrong. DST happens at 02:00 local time and therefore local time jumps from 1:59 to 3. This is correct. However, UTC time should not skip an extra hour as well.
Expected behavior
I write a similar snippet using Java and ZonedDateTime, and it appears to print the correct values (not the same date formats):
TZ date: 2024-03-31T00:00+01:00[Europe/Oslo], UTC date: 30 Mar 2024 23:00:00 GMT
TZ date: 2024-03-31T01:00+01:00[Europe/Oslo], UTC date: 31 Mar 2024 00:00:00 GMT
TZ date: 2024-03-31T03:00+02:00[Europe/Oslo], UTC date: 31 Mar 2024 01:00:00 GMT
TZ date: 2024-03-31T04:00+02:00[Europe/Oslo], UTC date: 31 Mar 2024 02:00:00 GMT
Also, doing it the other way around by adding hours to the Date objects and creating a new Dayjs object from that everytime works (append the following code inside the printDates function):
let currentDate = startOfDayWithDST.toDate();
for(let i = 0; i < 4; i++) {
currentTime = dayjs.tz(currentDate, "Europe/Oslo");
this.printDate(currentTime);
currentDate.setHours(currentDate.getHours() + 1)
}
TZ Date: 2024-03-31 00:00:00, UTC date: 2024-03-30T23:00:00.000Z
TZ Date: 2024-03-31 01:00:00, UTC date: 2024-03-31T00:00:00.000Z
TZ Date: 2024-03-31 03:00:00, UTC date: 2024-03-31T01:00:00.000Z
TZ Date: 2024-03-31 04:00:00, UTC date: 2024-03-31T02:00:00.000Z
Information
The text was updated successfully, but these errors were encountered: