fix(icalendar): Implement recursive RRULE value formatting

This commit is contained in:
2026-02-21 08:44:16 -08:00
parent 0ef8b9a77d
commit 6960f9ef91
2 changed files with 19 additions and 22 deletions

View File

@@ -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);
}