forked from GitHubMirrors/silverbullet-icalendar
fix(icalendar): Correctly map verbose RRULE keys to standard iCal keys
This commit is contained in:
26
icalendar.ts
26
icalendar.ts
@@ -8,6 +8,27 @@ const CACHE_KEY = "icalendar:lastSync";
|
|||||||
|
|
||||||
console.log(`[iCalendar] Plug script executing at top level (Version ${VERSION})`);
|
console.log(`[iCalendar] Plug script executing at top level (Version ${VERSION})`);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapping of verbose RRULE object keys to standard iCalendar shortened keys.
|
||||||
|
*/
|
||||||
|
const RRULE_KEY_MAP: Record<string, string> = {
|
||||||
|
"frequency": "FREQ",
|
||||||
|
"until": "UNTIL",
|
||||||
|
"count": "COUNT",
|
||||||
|
"interval": "INTERVAL",
|
||||||
|
"bysecond": "BYSECOND",
|
||||||
|
"byminute": "BYMINUTE",
|
||||||
|
"byhour": "BYHOUR",
|
||||||
|
"byday": "BYDAY",
|
||||||
|
"bymonthday": "BYMONTHDAY",
|
||||||
|
"byyearday": "BYYEARDAY",
|
||||||
|
"byweekno": "BYWEEKNO",
|
||||||
|
"bymonth": "BYMONTH",
|
||||||
|
"bysetpos": "BYSETPOS",
|
||||||
|
"wkst": "WKST",
|
||||||
|
"freq": "FREQ", // Just in case
|
||||||
|
};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Utility Functions
|
// Utility Functions
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -163,7 +184,10 @@ export function expandRecurrences(icsEvent: any, windowDays = 365): any[] {
|
|||||||
} else if (typeof rruleStr === "object" && rruleStr !== null) {
|
} else if (typeof rruleStr === "object" && rruleStr !== null) {
|
||||||
// Handle object rrule (e.g. from ts-ics) by converting back to string
|
// Handle object rrule (e.g. from ts-ics) by converting back to string
|
||||||
cleanRule = Object.entries(rruleStr)
|
cleanRule = Object.entries(rruleStr)
|
||||||
.map(([k, v]) => `${k.toUpperCase()}=${v}`)
|
.map(([k, v]) => {
|
||||||
|
const standardKey = RRULE_KEY_MAP[k.toLowerCase()] || k.toUpperCase();
|
||||||
|
return `${standardKey}=${v}`;
|
||||||
|
})
|
||||||
.join(";");
|
.join(";");
|
||||||
} else {
|
} else {
|
||||||
console.warn(`[iCalendar] Invalid rrule type (${typeof rruleStr}) for event "${icsEvent.summary || "Untitled"}". Treating as non-recurring.`);
|
console.warn(`[iCalendar] Invalid rrule type (${typeof rruleStr}) for event "${icsEvent.summary || "Untitled"}". Treating as non-recurring.`);
|
||||||
|
|||||||
Reference in New Issue
Block a user