Skip to content

Commit cbaf649

Browse files
authored
Merge pull request #3121 from ishanarora/patch-1
fix: recur correctly at start of Daylight Savings Time
2 parents 4d70a52 + 0c7edd5 commit cbaf649

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Task/Recurrence.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class Recurrence {
151151
// calculates in UTC.
152152
// The timezone is added again before returning the next date.
153153
after.utc(true);
154-
let next = window.moment(rrule.after(after.toDate()));
154+
let next = window.moment.utc(rrule.after(after.toDate()));
155155

156156
// If this is a monthly recurrence, treat it special.
157157
const asText = this.toText();
@@ -261,11 +261,15 @@ export class Recurrence {
261261
options.dtstart = after.startOf('day').toDate();
262262
rrule = new RRule(options);
263263

264-
return window.moment(rrule.after(after.toDate()));
264+
return window.moment.utc(rrule.after(after.toDate()));
265265
}
266266

267267
private static addTimezone(date: Moment): Moment {
268-
const localTimeZone = window.moment.utc(date).local(true);
268+
// Moment's local(true) method has a bug where it returns incorrect result if the input is of
269+
// the day of the year when DST kicks in and the time of day is before DST actually kicks in
270+
// (typically between midnight and very early morning, varying across geographies).
271+
// We workaround the bug by setting the time of day to noon before calling local(true)
272+
const localTimeZone = window.moment.utc(date).set({hour:12,minute:0,second:0,millisecond:0}).local(true);
269273

270274
return localTimeZone.startOf('day');
271275
}

0 commit comments

Comments
 (0)