From b82ceb7f4213e166c64ce643eef912b2ba4cd3a9 Mon Sep 17 00:00:00 2001 From: Billy <89012121+bu6n@users.noreply.github.com> Date: Fri, 24 Mar 2023 13:33:56 +0100 Subject: [PATCH] fix(moment): wrong time on the day when DST changes (#2374) Corrects issue with DST offset when using the moment or Luxon localizers Thanks to @bu6n for the fix #2296 --- src/localizers/moment.js | 6 ++++-- stories/resources/events.js | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/localizers/moment.js b/src/localizers/moment.js index 7421d28d3..7652b42b8 100644 --- a/src/localizers/moment.js +++ b/src/localizers/moment.js @@ -60,8 +60,10 @@ export default function (moment) { function getDstOffset(start, end) { // convert to moment, in case - const st = moment(start) - const ed = moment(end) + // Calculate the offset in the timezone of the Events (local) + // not in the timezone of the calendar (moment.tz) + const st = moment(start).local() + const ed = moment(end).local() // if not using moment timezone if (!moment.tz) { return st.toDate().getTimezoneOffset() - ed.toDate().getTimezoneOffset() diff --git a/stories/resources/events.js b/stories/resources/events.js index 90aaa4b4c..ccdc71a01 100644 --- a/stories/resources/events.js +++ b/stories/resources/events.js @@ -177,4 +177,28 @@ export default [ start: new Date(2015, 3, 14, 18, 30, 0), end: new Date(2015, 3, 14, 20, 0, 0), }, + { + id: 24, + title: 'DST ends on this day (Europe)', + start: new Date(2022, 9, 30, 0, 0, 0), + end: new Date(2022, 9, 30, 4, 30, 0), + }, + { + id: 25, + title: 'DST ends on this day (America)', + start: new Date(2022, 10, 6, 0, 0, 0), + end: new Date(2022, 10, 6, 4, 30, 0), + }, + { + id: 26, + title: 'DST starts on this day (America)', + start: new Date(2023, 2, 12, 0, 0, 0), + end: new Date(2023, 2, 12, 4, 30, 0), + }, + { + id: 27, + title: 'DST starts on this day (Europe)', + start: new Date(2023, 2, 26, 0, 0, 0), + end: new Date(2023, 2, 26, 4, 30, 0), + }, ]