#1271·dayjs

Add days across Daylight Saving Time

Author: MarkSFrancisCreated Dec 14, 2020Updated Sep 10, 2026

When 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