1
0
Fork 0

refactor: Refactor addEventsToCalendar to properly handle date validation and usage

- Updated the handling of start and end dates in the addEventsToCalendar function.
- Added validation checks directly on startDate and endDate to ensure they are valid before updating event properties.
- Improved logging for better traceability of event addition and date handling.

Note: The changes are intended to enhance the handling of date properties, but further testing is required to ensure full functionality.
This commit is contained in:
Ryan Mwangi 2024-11-08 02:21:22 +03:00
parent 1bb1db7326
commit db78a0121e
1 changed files with 17 additions and 2 deletions

View File

@ -64,10 +64,25 @@ const addEventsToCalendar = (calendarComponent, results) => {
const newEvent = new ICAL.Component('vevent'); const newEvent = new ICAL.Component('vevent');
console.log(`Adding event: ${vevent.summary} to calendar.`); console.log(`Adding event: ${vevent.summary} to calendar.`);
// Get start and end dates directly
const startDate = vevent.startDate;
const endDate = vevent.endDate;
// 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
}
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', vevent.startDate.toICALString()); newEvent.updatePropertyWithValue('dtstart', startDate.toICALString());
newEvent.updatePropertyWithValue('dtend', vevent.endDate.toICALString()); newEvent.updatePropertyWithValue('dtend', endDate.toICALString());
calendarComponent.addSubcomponent(newEvent); calendarComponent.addSubcomponent(newEvent);
}); });