Skip to content

Commit

Permalink
fix(moment): wrong time on the day when DST changes (jquense#2374)
Browse files Browse the repository at this point in the history
Corrects issue with DST offset when using the moment or Luxon localizers
Thanks to @bu6n for the fix

jquense#2296
  • Loading branch information
bu6n committed Mar 24, 2023
1 parent 76be38e commit b82ceb7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/localizers/moment.js
Expand Up @@ -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()
Expand Down
24 changes: 24 additions & 0 deletions stories/resources/events.js
Expand Up @@ -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),
},
]

0 comments on commit b82ceb7

Please sign in to comment.