Skip to content

Commit

Permalink
fix: wrong time on the day when DST changes
Browse files Browse the repository at this point in the history
Fixes #2296, but only for the `moment` localizer. Still have to find a fix for `luxon`.
  • Loading branch information
bu6n committed Feb 27, 2023
1 parent 76be38e commit 17333c3
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 17333c3

Please sign in to comment.