Hotfix - CalDAV/Wraps timezone addition in try catch (#8453)

* Wraps timezone addition in try catch

* Suggestion accepted

Co-authored-by: Alex van Andel <me@alexvanandel.com>

---------

Co-authored-by: Alex van Andel <me@alexvanandel.com>
pull/8457/head
Syed Ali Shahbaz 2023-04-22 16:28:03 +05:30 committed by GitHub
parent dd8968d0e7
commit 2eed750ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 13 deletions

View File

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