Skip to content

Commit 17333c3

Browse files
committed
fix: wrong time on the day when DST changes
Fixes jquense#2296, but only for the `moment` localizer. Still have to find a fix for `luxon`.
1 parent 76be38e commit 17333c3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/localizers/moment.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ export default function (moment) {
6060

6161
function getDstOffset(start, end) {
6262
// convert to moment, in case
63-
const st = moment(start)
64-
const ed = moment(end)
63+
// Calculate the offset in the timezone of the Events (local)
64+
// not in the timezone of the calendar (moment.tz)
65+
const st = moment(start).local()
66+
const ed = moment(end).local()
6567
// if not using moment timezone
6668
if (!moment.tz) {
6769
return st.toDate().getTimezoneOffset() - ed.toDate().getTimezoneOffset()

stories/resources/events.js

+24
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,28 @@ export default [
177177
start: new Date(2015, 3, 14, 18, 30, 0),
178178
end: new Date(2015, 3, 14, 20, 0, 0),
179179
},
180+
{
181+
id: 24,
182+
title: 'DST ends on this day (Europe)',
183+
start: new Date(2022, 9, 30, 0, 0, 0),
184+
end: new Date(2022, 9, 30, 4, 30, 0),
185+
},
186+
{
187+
id: 25,
188+
title: 'DST ends on this day (America)',
189+
start: new Date(2022, 10, 6, 0, 0, 0),
190+
end: new Date(2022, 10, 6, 4, 30, 0),
191+
},
192+
{
193+
id: 26,
194+
title: 'DST starts on this day (America)',
195+
start: new Date(2023, 2, 12, 0, 0, 0),
196+
end: new Date(2023, 2, 12, 4, 30, 0),
197+
},
198+
{
199+
id: 27,
200+
title: 'DST starts on this day (Europe)',
201+
start: new Date(2023, 2, 26, 0, 0, 0),
202+
end: new Date(2023, 2, 26, 4, 30, 0),
203+
},
180204
]

0 commit comments

Comments
 (0)