forked from ryanmwangi/CalMerger
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:
parent
db78a0121e
commit
11a4efe30b
1 changed files with 9 additions and 9 deletions
18
server.js
18
server.js
|
@ -66,23 +66,23 @@ const addEventsToCalendar = (calendarComponent, results) => {
|
||||||
console.log(`Adding event: ${vevent.summary} to calendar.`);
|
console.log(`Adding event: ${vevent.summary} to calendar.`);
|
||||||
|
|
||||||
// Get start and end dates directly
|
// Get start and end dates directly
|
||||||
const startDate = vevent.startDate;
|
const startDate = vevent.startDate && ICAL.Time.fromJSDate(vevent.startDate.toJSDate());
|
||||||
const endDate = vevent.endDate;
|
const endDate = vevent.endDate && ICAL.Time.fromJSDate(vevent.endDate.toJSDate());
|
||||||
|
|
||||||
// Log the start and end dates
|
// Log the start and end dates
|
||||||
console.log(`Start Date: ${startDate}`);
|
console.log(`Start Date: ${startDate}`);
|
||||||
console.log(`End Date: ${endDate}`);
|
console.log(`End Date: ${endDate}`);
|
||||||
|
|
||||||
// Check if the dates are valid
|
// // Check if the dates are valid
|
||||||
if (!startDate.isValid() || !endDate.isValid()) {
|
// if (!startDate || !endDate || !startDate.isValid() || !endDate.isValid()) {
|
||||||
console.warn(`Invalid date for event: ${vevent.summary}`);
|
// console.warn(`Invalid date for event: ${vevent.summary}`);
|
||||||
return; // Skip this event or handle it accordingly
|
// return; // Skip or handle accordingly
|
||||||
}
|
// }
|
||||||
|
|
||||||
newEvent.updatePropertyWithValue('uid', vevent.uid);
|
newEvent.updatePropertyWithValue('uid', vevent.uid);
|
||||||
newEvent.updatePropertyWithValue('summary', result.override ? result.prefix : `${result.prefix} ${vevent.summary}`);
|
newEvent.updatePropertyWithValue('summary', result.override ? result.prefix : `${result.prefix} ${vevent.summary}`);
|
||||||
newEvent.updatePropertyWithValue('dtstart', startDate.toICALString());
|
newEvent.updatePropertyWithValue('dtstart', startDate);
|
||||||
newEvent.updatePropertyWithValue('dtend', endDate.toICALString());
|
newEvent.updatePropertyWithValue('dtend', endDate);
|
||||||
|
|
||||||
calendarComponent.addSubcomponent(newEvent);
|
calendarComponent.addSubcomponent(newEvent);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue