diff --git a/packages/lib/CalendarService.ts b/packages/lib/CalendarService.ts index fdd88eed1a..9d1a8316b6 100644 --- a/packages/lib/CalendarService.ts +++ b/packages/lib/CalendarService.ts @@ -293,6 +293,7 @@ export default abstract class BaseCalendarService implements Calendar { dateTo: string, selectedCalendars: IntegrationCalendar[] ): Promise { + const startISOString = new Date(dateFrom).toISOString(); const objects = ( await Promise.all( selectedCalendars @@ -306,7 +307,7 @@ export default abstract class BaseCalendarService implements Calendar { headers: this.headers, expand: true, timeRange: { - start: new Date(dateFrom).toISOString(), + start: startISOString, end: new Date(dateTo).toISOString(), }, }) @@ -359,15 +360,24 @@ export default abstract class BaseCalendarService implements Calendar { const start = dayjs(dateFrom); const end = dayjs(dateTo); - const iterator = event.iterator(); - let current; + const startDate = ICAL.Time.fromDateTimeString(startISOString); + startDate.hour = event.startDate.hour; + startDate.minute = event.startDate.minute; + startDate.second = event.startDate.second; + const iterator = event.iterator(startDate); + let current: ICAL.Time; let currentEvent; - let currentStart; + let currentStart = null; let currentError; - do { + while ( + maxIterations > 0 && + (currentStart === null || currentStart.isAfter(end) === false) && + // this iterator was poorly implemented, normally done is expected to be + // returned + (current = iterator.next()) + ) { maxIterations -= 1; - current = iterator.next(); try { // @see https://github.com/mozilla-comm/ical.js/issues/514 @@ -395,7 +405,7 @@ export default abstract class BaseCalendarService implements Calendar { end: dayjs(currentEvent.endDate.toJSDate()).toISOString(), }); } - } while (maxIterations > 0 && currentStart.isAfter(end) === false); + } if (maxIterations <= 0) { console.warn("could not find any occurrence for recurring event in 365 iterations"); } diff --git a/packages/types/ical.d.ts b/packages/types/ical.d.ts index 2fa435016c..775460f004 100644 --- a/packages/types/ical.d.ts +++ b/packages/types/ical.d.ts @@ -121,6 +121,7 @@ declare module "ical.js" { public static fromString(str: string): Time; public static fromJSDate(aDate: Date | null, useUTC: boolean): Time; public static fromData(aData: TimeJsonData): Time; + public static fromDateTimeString(aDate: string): Time; public now(): Time;