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
Computing difference between two dates, which one was subtracted 1000 days from, returns 999 days, if the date is on the boundary of daylight-saving changes:
This problem has been caused by 969aced. It adds/subtracts days using the local time zone. Previously, days were added/subtracted in UTC (using UNIX time), like hours and shorter units. While it helps people, who were not aware of Day.js working in the local time zone (#262 and #329), it also made Day.js inconsistent, because computing difference in days is still done in UTC (using UNIX time).
Once add() and subtract() methods were modified to expect the day count in the local time zone, the diff() method should be modified to return the day count in the local time zone too.
Adding/subtracting hours and shorter units happens in UTC, computing the difference in these units happens in UTC as well. Handling hours and shorter units by Day.js is consistent.
The tests were executed in Node.js 8 in the time zone "Europe/Prague" using Day.js 1.7.7 and Moment.js 2.22.2.
The text was updated successfully, but these errors were encountered:
Related: Adding one 'day' on a daylight-changing day is broken. It adds 24 hours, no matter if that day has 23, 24 or 25 hours.
let a = dayjs('2018-11-04');
console.log(a);
// h {$d: Sun Nov 04 2018 00:00:00 GMT-0400 (Eastern Daylight Time), $y: 2018, $M: 10, $D: 4, ...}
a = a.add(1, 'day');
console.log(a);
// h {$d: Sun Nov 04 2018 23:00:00 GMT-0500 (Eastern Standard Time), $y: 2018, $M: 10, $D: 4, …}
Computing difference between two dates, which one was subtracted 1000 days from, returns 999 days, if the date is on the boundary of daylight-saving changes:
Moment.js computes the difference correctly. Notice, that the difference in hours is correct in Day.js too:
This problem has been caused by 969aced. It adds/subtracts days using the local time zone. Previously, days were added/subtracted in UTC (using UNIX time), like hours and shorter units. While it helps people, who were not aware of Day.js working in the local time zone (#262 and #329), it also made Day.js inconsistent, because computing difference in days is still done in UTC (using UNIX time).
Once
add()
andsubtract()
methods were modified to expect the day count in the local time zone, thediff()
method should be modified to return the day count in the local time zone too.Adding/subtracting hours and shorter units happens in UTC, computing the difference in these units happens in UTC as well. Handling hours and shorter units by Day.js is consistent.
The tests were executed in Node.js 8 in the time zone "Europe/Prague" using Day.js 1.7.7 and Moment.js 2.22.2.
The text was updated successfully, but these errors were encountered: