fix(icalendar): Support object rrule by converting to string

This commit is contained in:
2026-02-20 11:37:48 -08:00
parent 6b12c26497
commit 426d6d1dc6
2 changed files with 19 additions and 10 deletions

View File

@@ -154,14 +154,23 @@ export function expandRecurrences(icsEvent: any, windowDays = 365): any[] {
const rruleStr = icsEvent.rrule || (icsEvent as any).recurrenceRule;
if (!rruleStr) return [icsEvent];
if (typeof rruleStr !== "string") {
console.warn(`[iCalendar] Invalid rrule type (${typeof rruleStr}) for event "${icsEvent.summary || "Untitled"}". Treating as non-recurring.`);
return [icsEvent];
}
try {
const set = new RRuleSet();
const cleanRule = rruleStr.replace(/^RRULE:/i, "");
let cleanRule = "";
if (typeof rruleStr === "string") {
cleanRule = rruleStr.replace(/^RRULE:/i, "");
} else if (typeof rruleStr === "object" && rruleStr !== null) {
// Handle object rrule (e.g. from ts-ics) by converting back to string
cleanRule = Object.entries(rruleStr)
.map(([k, v]) => `${k.toUpperCase()}=${v}`)
.join(";");
} else {
console.warn(`[iCalendar] Invalid rrule type (${typeof rruleStr}) for event "${icsEvent.summary || "Untitled"}". Treating as non-recurring.`);
return [icsEvent];
}
// We need to provide DTSTART if it's not in the string
// We need to provide DTSTART if it's not in the string
const dtstart = new Date(icsEvent.start.includes("Z") ? icsEvent.start : icsEvent.start + "Z");

View File

@@ -196,13 +196,13 @@ Deno.test("expandRecurrences - object rrule (Reproduction of missing events)", (
try {
const results = expandRecurrences(icsEvent, 30);
// Currently, it returns [icsEvent] (length 1) and logs a warning.
// This confirms that it is NOT expanding it.
assertEquals(results.length, 1);
// Should now return multiple occurrences
assert(results.length > 1, `Expected > 1 occurrences, got ${results.length}`);
assertEquals(results[0].recurrent, true);
} finally {
console.warn = originalConsoleWarn;
}
assert(warningLogged, "Should have logged a warning for object rrule");
assert(!warningLogged, "Should NOT have logged a warning for object rrule");
});