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");