From d15d0be70738d8322dfffec1c1ea0acc692b2a6b Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Tue, 19 Nov 2024 19:03:06 +0300 Subject: [PATCH] feat(calendar): extract and include X-WR-TIMEZONE if available --- src/calendarUtil.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/calendarUtil.js b/src/calendarUtil.js index 13e2e97..4d6df81 100644 --- a/src/calendarUtil.js +++ b/src/calendarUtil.js @@ -38,20 +38,34 @@ export function createCalendarComponent(name) { // Add events to the calendar component export function addEventsToCalendar(calendarComponent, results, overrideFlag = false) { + let defaultTimeZone = null; // To store the first found X-WR-TIMEZONE + results.forEach((result) => { try { const parsed = ICAL.parse(result.data); const component = new ICAL.Component(parsed); - - // Extract METHOD from the parsed data (if available) - const method = component.getFirstPropertyValue('method'); - if (method) { - console.log(`Extracted METHOD: ${method}`); - // Only add the METHOD property once - if (!calendarComponent.getFirstPropertyValue('method')) { - calendarComponent.updatePropertyWithValue('method', method.toUpperCase()); - } - } + + // Extract METHOD from the parsed data (if available) + const method = component.getFirstPropertyValue('method'); + if (method) { + console.log(`Extracted METHOD: ${method}`); + // Only add the METHOD property once + if (!calendarComponent.getFirstPropertyValue('method')) { + calendarComponent.updatePropertyWithValue('method', method.toUpperCase()); + } + } + // Extract X-WR-TIMEZONE if available + const wrTimeZone = component.getFirstPropertyValue('x-wr-timezone'); + if (wrTimeZone) { + console.log(`Extracted X-WR-TIMEZONE: ${wrTimeZone}`); + // Set it as the default if not already set + if (!defaultTimeZone) { + defaultTimeZone = wrTimeZone; + if (!calendarComponent.getFirstPropertyValue('x-wr-timezone')) { + calendarComponent.updatePropertyWithValue('x-wr-timezone', defaultTimeZone); + } + } + } // Extract and add VTIMEZONE components const timezones = component.getAllSubcomponents('vtimezone');