forked from GitHubMirrors/silverbullet-icalendar
fix(icalendar): Implement recursive RRULE value formatting
This commit is contained in:
18
icalendar.ts
18
icalendar.ts
@@ -30,15 +30,25 @@ const RRULE_KEY_MAP: Record<string, string> = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats an RRULE value for the string representation.
|
||||
* Specifically handles Date objects and nested date objects from ts-ics.
|
||||
* Robustly formats an RRULE value for its string representation.
|
||||
* Handles:
|
||||
* - Arrays: joins elements with commas (recursive)
|
||||
* - Date objects: formats as YYYYMMDDTHHMMSSZ
|
||||
* - Objects: extracts .date, .day, or .value properties (recursive)
|
||||
* - Primitives: stringifies directly
|
||||
*/
|
||||
function formatRRuleValue(v: any): string {
|
||||
if (Array.isArray(v)) {
|
||||
return v.map((item) => formatRRuleValue(item)).join(",");
|
||||
}
|
||||
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";
|
||||
if (typeof v === "object" && v !== null) {
|
||||
const val = v.date || v.day || v.value;
|
||||
if (val !== undefined) {
|
||||
return formatRRuleValue(val);
|
||||
}
|
||||
}
|
||||
return String(v);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user