From 11a4efe30b65545d68dbc3a9e979408e4f31d8c8 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Fri, 8 Nov 2024 14:23:30 +0300 Subject: [PATCH] fix: ensure valid date-time handling in event components - Resolved calendar merging error where ICAL.js rejected formatted date-time strings by refactoring and initialization to use for accurate timezone conversion. - Updated and to receive ICAL.Time objects directly, ensuring proper format consistency and timezone handling in event components. --- server.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server.js b/server.js index 4636b66..64bec33 100644 --- a/server.js +++ b/server.js @@ -66,23 +66,23 @@ const addEventsToCalendar = (calendarComponent, results) => { console.log(`Adding event: ${vevent.summary} to calendar.`); // Get start and end dates directly - const startDate = vevent.startDate; - const endDate = vevent.endDate; + const startDate = vevent.startDate && ICAL.Time.fromJSDate(vevent.startDate.toJSDate()); + const endDate = vevent.endDate && ICAL.Time.fromJSDate(vevent.endDate.toJSDate()); // Log the start and end dates console.log(`Start Date: ${startDate}`); console.log(`End Date: ${endDate}`); - // Check if the dates are valid - if (!startDate.isValid() || !endDate.isValid()) { - console.warn(`Invalid date for event: ${vevent.summary}`); - return; // Skip this event or handle it accordingly - } + // // Check if the dates are valid + // if (!startDate || !endDate || !startDate.isValid() || !endDate.isValid()) { + // console.warn(`Invalid date for event: ${vevent.summary}`); + // return; // Skip or handle accordingly + // } newEvent.updatePropertyWithValue('uid', vevent.uid); newEvent.updatePropertyWithValue('summary', result.override ? result.prefix : `${result.prefix} ${vevent.summary}`); - newEvent.updatePropertyWithValue('dtstart', startDate.toICALString()); - newEvent.updatePropertyWithValue('dtend', endDate.toICALString()); + newEvent.updatePropertyWithValue('dtstart', startDate); + newEvent.updatePropertyWithValue('dtend', endDate); calendarComponent.addSubcomponent(newEvent); });