Add days across Daylight Saving Time
See original GitHub issueWhen adding days to a time, it’s assuming each day is 24 hours long. This is not a correct assumption when crossing over daylight saving time.
Steps to recreate
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import tz from 'dayjs/plugin/timezone';
dayjs.extend(utc);
dayjs.extend(tz);
// 2020-10-25 is when DST starts in Europe/London (clocks go back by one hour).
// This means that 2020-10-25 is a day that's only 23 hours long
const date1 = dayjs.tz('2020-10-24', 'Europe/London').add(2, 'day').toISOString();
const date2 = dayjs.tz('2020-10-26', 'Europe/London').toISOString();
// Prints
// {
// date1: '2020-10-25T23:00:00.000Z',
// date2: '2020-10-26T00:00:00.000Z'
// }
console.log({ date1, date2 });
Expected behavior
date1 and date2 should be the same, as adding the number of “days” to the date should’ve allowed for the fact that not all days are 24 hours.
Information
- Day.js Version: v1.9.2
- OS: Windows 10 20H2
- Browser: Chromium: 87.0.4280.101
- Time zone: (UTC -04:00) Santiago
Issue Analytics
- State:
- Created 3 years ago
- Reactions:23
- Comments:8
Top Results From Across the Web
Moment.js issue adding days with Daylight Savings Time
Moment.js issue adding days with Daylight Savings Time · 1.I create a moment date: var m = moment(new Date(2014, 9, 18, 0, 0,...
Read more >daylight savings, addDays and addToTime
Hello, I have a power app, which creates events with the possibility to automatically create follow ups on a regular basis, ...
Read more >Daylight Saving Time 2022: When Does the Time Change?
Daylight Saving Time ends on Sunday, November 6, 2022, at 2:00 A.M. On Saturday night, clocks are set back one hour (i.e., gaining...
Read more >Daylight Saving Time 2023: When Does the Time Change?
The first Sunday in November is when Daylight Saving Time ends in most areas of the U.S., so in 2023 we “fall back”...
Read more >How Does Daylight Saving Time Work? - Time and Date
In the fall (autumn), the DST period usually ends, and our clocks are set back to standard time again. In terms of hours...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

We completely switched our project to dayjs and at the end noticed that dayjs does not support the daylight saving time. I can only warn against using this library. Operations such as add cause unexpected results. As soon as a calculation goes over the limit of the time change, the result is wrong. We will continue to use moment.js. This library can only be used in countries without daylight saving time. Example:
dayjs(‘25-10-2020’, ‘DD-MM-YYYY’) .tz(‘Europe/Berlin’) .add(1, ‘day’) .diff(dayjs(‘26-10-2020’, ‘DD-MM-YYYY’).tz(‘Europe/Berlin’), ‘days’) .toString()
result = -3600000
This is an important issue for us, but there is a workaround possible…
datemethodtzmethod to “reset” TZ (datemethod doesn’t update theoffsetvalue)