forked from GitHubMirrors/silverbullet-icalendar
fix(icalendar): Support object rrule by converting to string
This commit is contained in:
21
icalendar.ts
21
icalendar.ts
@@ -154,14 +154,23 @@ export function expandRecurrences(icsEvent: any, windowDays = 365): any[] {
|
|||||||
const rruleStr = icsEvent.rrule || (icsEvent as any).recurrenceRule;
|
const rruleStr = icsEvent.rrule || (icsEvent as any).recurrenceRule;
|
||||||
if (!rruleStr) return [icsEvent];
|
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 {
|
try {
|
||||||
const set = new RRuleSet();
|
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
|
// 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");
|
const dtstart = new Date(icsEvent.start.includes("Z") ? icsEvent.start : icsEvent.start + "Z");
|
||||||
|
|||||||
@@ -196,13 +196,13 @@ Deno.test("expandRecurrences - object rrule (Reproduction of missing events)", (
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const results = expandRecurrences(icsEvent, 30);
|
const results = expandRecurrences(icsEvent, 30);
|
||||||
// Currently, it returns [icsEvent] (length 1) and logs a warning.
|
// Should now return multiple occurrences
|
||||||
// This confirms that it is NOT expanding it.
|
assert(results.length > 1, `Expected > 1 occurrences, got ${results.length}`);
|
||||||
assertEquals(results.length, 1);
|
assertEquals(results[0].recurrent, true);
|
||||||
} finally {
|
} finally {
|
||||||
console.warn = originalConsoleWarn;
|
console.warn = originalConsoleWarn;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(warningLogged, "Should have logged a warning for object rrule");
|
assert(!warningLogged, "Should NOT have logged a warning for object rrule");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user