forked from GitHubMirrors/silverbullet-icalendar
fix(icalendar): Correctly format nested objects (dates) in RRULE properties
This commit is contained in:
16
icalendar.ts
16
icalendar.ts
@@ -29,6 +29,20 @@ const RRULE_KEY_MAP: Record<string, string> = {
|
||||
"freq": "FREQ", // Just in case
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats an RRULE value for the string representation.
|
||||
* Specifically handles Date objects and nested date objects from ts-ics.
|
||||
*/
|
||||
function formatRRuleValue(v: any): string {
|
||||
if (v instanceof Date) {
|
||||
return v.toISOString().replace(/[-:]/g, "").split(".")[0] + "Z";
|
||||
}
|
||||
if (typeof v === "object" && v !== null && v.date instanceof Date) {
|
||||
return v.date.toISOString().replace(/[-:]/g, "").split(".")[0] + "Z";
|
||||
}
|
||||
return String(v);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Utility Functions
|
||||
// ============================================================================
|
||||
@@ -186,7 +200,7 @@ export function expandRecurrences(icsEvent: any, windowDays = 365): any[] {
|
||||
cleanRule = Object.entries(rruleStr)
|
||||
.map(([k, v]) => {
|
||||
const standardKey = RRULE_KEY_MAP[k.toLowerCase()] || k.toUpperCase();
|
||||
return `${standardKey}=${v}`;
|
||||
return `${standardKey}=${formatRRuleValue(v)}`;
|
||||
})
|
||||
.join(";");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user