feat(calendar): extract and include X-WR-TIMEZONE if available

This commit is contained in:
Ryan Mwangi 2024-11-19 19:03:06 +03:00
parent 5e3e8eab5b
commit d15d0be707
1 changed files with 24 additions and 10 deletions

View File

@ -38,6 +38,8 @@ export function createCalendarComponent(name) {
// Add events to the calendar component // Add events to the calendar component
export function addEventsToCalendar(calendarComponent, results, overrideFlag = false) { export function addEventsToCalendar(calendarComponent, results, overrideFlag = false) {
let defaultTimeZone = null; // To store the first found X-WR-TIMEZONE
results.forEach((result) => { results.forEach((result) => {
try { try {
const parsed = ICAL.parse(result.data); const parsed = ICAL.parse(result.data);
@ -52,6 +54,18 @@ export function addEventsToCalendar(calendarComponent, results, overrideFlag = f
calendarComponent.updatePropertyWithValue('method', method.toUpperCase()); 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 // Extract and add VTIMEZONE components
const timezones = component.getAllSubcomponents('vtimezone'); const timezones = component.getAllSubcomponents('vtimezone');