diff --git a/static/js/upcoming.js b/static/js/upcoming.js index cc8ad0b..f031b4d 100644 --- a/static/js/upcoming.js +++ b/static/js/upcoming.js @@ -4,7 +4,7 @@ import ICAL from "https://unpkg.com/ical.js/dist/ical.min.js"; * Parse an ICS calendar and return upcoming event occurrences. * * @param {string} icsText The contents of the .ics file - * @param {Date} now Events must start after this date + * @param {Date} now Events must still be running at this date * @param {number} maxEvents Maximum number of events to return * @param {number} maxDays Maximum number of days into the future * @returns {{start: Date, name: string, url: string}[]} url is empty when the event has no URL @@ -38,17 +38,19 @@ function getUpcomingEvents(icsText, now, maxEvents, maxDays) { break; } - const start = occurrence.toJSDate(); - // Recurrences are chronological, so we're done // once we pass the end of our search window. - if (start > end) { + if (occurrence.toJSDate() > end) { break; } - if (start > now) { + // Details resolve the times of occurrences overridden by RECURRENCE-ID. + const details = event.getOccurrenceDetails(occurrence); + + // A running event stays listed until it is over, so filter on its end. + if (details.endDate.toJSDate() > now) { events.push({ - start, + start: details.startDate.toJSDate(), name: event.summary ?? "", url, }); @@ -57,7 +59,7 @@ function getUpcomingEvents(icsText, now, maxEvents, maxDays) { } else { const start = event.startDate.toJSDate(); - if (start > now && start <= end) { + if (start <= end && event.endDate.toJSDate() > now) { events.push({ start, name: event.summary ?? "",