Skip to content

Commit 68a80ee

Browse files
author
Koen Konst
committed
Fixed an issue with slicedMultiDay events and datekey generation for exdates and recurrences
1 parent 4357221 commit 68a80ee

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

modules/default/calendar/calendar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ Module.register("calendar", {
664664

665665
event.startDate = midnight.unix();
666666
count += 1;
667-
midnight = midnight.clone().add(1, "day").endOf("day").unix(); // next day
667+
midnight = midnight.clone().add(1, "day").endOf("day"); // next day
668668
}
669669
// Last day
670670
event.title += ` (${count}/${maxCount})`;

modules/default/calendar/calendarfetcherutils.js

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ const CalendarFetcherUtils = {
6767
return filter;
6868
},
6969

70+
/**
71+
* Get local timezone.
72+
* This method makes it easier to test if different timezones cause problems by changing this implementation.
73+
* @returns {string} timezone
74+
*/
75+
getLocalTimezone () {
76+
return "America/Los_Angeles";
77+
},
78+
7079
/**
7180
* This function returns a list of moments for a recurring event.
7281
* @param {object} event the current event which is a recurring event
@@ -114,7 +123,7 @@ const CalendarFetcherUtils = {
114123

115124
// Dates are returned in UTC timezone but with localdatetime because tzid is null.
116125
// So we map the date to a moment using the original timezone of the event.
117-
return dates.map((d) => (event.start.tz ? moment.tz(d, "UTC").tz(event.start.tz, true) : moment.tz(d, "UTC").tz(moment.tz.guess(), true)));
126+
return dates.map((d) => (event.start.tz ? moment.tz(d, "UTC").tz(event.start.tz, true) : moment.tz(d, "UTC").tz(CalendarFetcherUtils.getLocalTimezone(), true)));
118127
},
119128

120129
/**
@@ -202,10 +211,10 @@ const CalendarFetcherUtils = {
202211
for (let m in moments) {
203212
let curEvent = event;
204213
let showRecurrence = true;
205-
let recurringEventStartMoment = moments[m].tz(moment.tz.guess()).clone();
214+
let recurringEventStartMoment = moments[m].tz(CalendarFetcherUtils.getLocalTimezone()).clone();
206215
let recurringEventEndMoment = recurringEventStartMoment.clone().add(durationMs, "ms");
207216

208-
let dateKey = CalendarFetcherUtils.getDateKeyFromDate(recurringEventStartMoment.toDate());
217+
let dateKey = recurringEventStartMoment.tz("UTC").format("YYYY-MM-DD");
209218

210219
Log.debug("event date dateKey=", dateKey);
211220
// For each date that we're checking, it's possible that there is a recurrence override for that one day.
@@ -217,22 +226,22 @@ const CalendarFetcherUtils = {
217226
curEvent = curEvent.recurrences[dateKey];
218227
// Some event start/end dates don't have timezones
219228
if (curEvent.start.tz) {
220-
recurringEventStartMoment = moment(curEvent.start).tz(curEvent.start.tz).tz(moment.tz.guess());
229+
recurringEventStartMoment = moment(curEvent.start).tz(curEvent.start.tz).tz(CalendarFetcherUtils.getLocalTimezone());
221230
} else {
222-
recurringEventStartMoment = moment(curEvent.start).tz(moment.tz.guess());
231+
recurringEventStartMoment = moment(curEvent.start).tz(CalendarFetcherUtils.getLocalTimezone());
223232
}
224233
if (curEvent.end.tz) {
225-
recurringEventEndMoment = moment(curEvent.end).tz(curEvent.end.tz).tz(moment.tz.guess());
234+
recurringEventEndMoment = moment(curEvent.end).tz(curEvent.end.tz).tz(CalendarFetcherUtils.getLocalTimezone());
226235
} else {
227-
recurringEventEndMoment = moment(curEvent.end).tz(moment.tz.guess());
236+
recurringEventEndMoment = moment(curEvent.end).tz(CalendarFetcherUtils.getLocalTimezone());
228237
}
229238
} else {
230239
Log.debug("recurrence key ", dateKey, " doesn't match");
231240
}
232241
}
233242
// If there's no recurrence override, check for an exception date. Exception dates represent exceptions to the rule.
234243
if (curEvent.exdate !== undefined) {
235-
Log.debug("have datekey=", dateKey, " exdates=", curEvent.exdate);
244+
console.log("have datekey=", dateKey, " exdates=", curEvent.exdate);
236245
if (curEvent.exdate[dateKey] !== undefined) {
237246
// This date is an exception date, which means we should skip it in the recurrence pattern.
238247
showRecurrence = false;
@@ -335,31 +344,6 @@ const CalendarFetcherUtils = {
335344
return newEvents;
336345
},
337346

338-
/**
339-
* get the exdate/recurrence hash key from the date object
340-
* BEFORE calling rrule.between
341-
* @param {Date} date The date of the event
342-
* @returns {string} date key in the format YYYY-MM-DD
343-
*/
344-
getDateKeyFromDate (date) {
345-
// get our runtime timezone offset
346-
let startday = date.getDate();
347-
Log.debug(" day of month=", (`0${startday}`).slice(-2), ` start time=${date.toString().split(" ")[4].slice(0, 2)}`);
348-
Log.debug("date string= ", date.toString());
349-
Log.debug("date iso string ", date.toISOString());
350-
// if the dates are different
351-
if (date.toString().slice(8, 10) < date.toISOString().slice(8, 10)) {
352-
startday = date.toString().slice(8, 10);
353-
Log.debug("< ", startday);
354-
} else { // tostring is more
355-
if (date.toString().slice(8, 10) > date.toISOString().slice(8, 10)) {
356-
startday = date.toISOString().slice(8, 10);
357-
Log.debug("> ", startday);
358-
}
359-
}
360-
return date.toISOString().substring(0, 8) + (`0${startday}`).slice(-2);
361-
},
362-
363347
/**
364348
* Gets the title from the event.
365349
* @param {object} event The event object to check.

0 commit comments

Comments
 (0)