From 2eed750ef64bc8cacabd2ea2e74e5d86a86733a9 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Sat, 22 Apr 2023 16:28:03 +0530 Subject: [PATCH] Hotfix - CalDAV/Wraps timezone addition in try catch (#8453) * Wraps timezone addition in try catch * Suggestion accepted Co-authored-by: Alex van Andel --------- Co-authored-by: Alex van Andel --- packages/lib/CalendarService.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/lib/CalendarService.ts b/packages/lib/CalendarService.ts index 410bb6f322..d4c0f62049 100644 --- a/packages/lib/CalendarService.ts +++ b/packages/lib/CalendarService.ts @@ -323,20 +323,26 @@ export default abstract class BaseCalendarService implements Calendar { const tzid: string | undefined = vevent?.getFirstPropertyValue("tzid") || isUTC ? "UTC" : timezone; // In case of icalendar, when only tzid is available without vtimezone, we need to add vtimezone explicitly to take care of timezone diff if (!vcalendar.getFirstSubcomponent("vtimezone") && tzid) { - const timezoneComp = new ICAL.Component("vtimezone"); - timezoneComp.addPropertyWithValue("tzid", tzid); - const standard = new ICAL.Component("standard"); - // get timezone offset - const tzoffsetfrom = dayjs(event.startDate.toJSDate()).tz(tzid).format("Z"); - const tzoffsetto = dayjs(event.endDate.toJSDate()).tz(tzid).format("Z"); + try { + const timezoneComp = new ICAL.Component("vtimezone"); + timezoneComp.addPropertyWithValue("tzid", tzid); + const standard = new ICAL.Component("standard"); - // set timezone offset - standard.addPropertyWithValue("tzoffsetfrom", tzoffsetfrom); - standard.addPropertyWithValue("tzoffsetto", tzoffsetto); - // provide a standard dtstart - standard.addPropertyWithValue("dtstart", "1601-01-01T00:00:00"); - timezoneComp.addSubcomponent(standard); - vcalendar.addSubcomponent(timezoneComp); + // get timezone offset + const tzoffsetfrom = dayjs(event.startDate.toJSDate()).tz(tzid).format("Z"); + const tzoffsetto = dayjs(event.endDate.toJSDate()).tz(tzid).format("Z"); + + // set timezone offset + standard.addPropertyWithValue("tzoffsetfrom", tzoffsetfrom); + standard.addPropertyWithValue("tzoffsetto", tzoffsetto); + // provide a standard dtstart + standard.addPropertyWithValue("dtstart", "1601-01-01T00:00:00"); + timezoneComp.addSubcomponent(standard); + vcalendar.addSubcomponent(timezoneComp); + } catch (e) { + // Adds try-catch to ensure the code proceeds when Apple Calendar provides non-standard TZIDs + console.log("error in adding vtimezone", e); + } } const vtimezone = vcalendar.getFirstSubcomponent("vtimezone");