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.
This commit is contained in:
Ryan Mwangi 2024-11-08 14:23:30 +03:00
parent db78a0121e
commit 11a4efe30b

View file

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