From 1c529c0e7d47d02f578fcec6f3b7b8306b2ab905 Mon Sep 17 00:00:00 2001 From: SASAGAWA Kiyoshi Date: Sun, 11 Feb 2024 05:30:37 +0900 Subject: [PATCH] Fix: iCal integration fails with all-day events (#2883) --------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> --- src/widgets/calendar/integrations/ical.jsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/widgets/calendar/integrations/ical.jsx b/src/widgets/calendar/integrations/ical.jsx index ec6427916..05d059c72 100644 --- a/src/widgets/calendar/integrations/ical.jsx +++ b/src/widgets/calendar/integrations/ical.jsx @@ -52,15 +52,17 @@ export default function Integration({ config, params, setEvents, hideErrors, tim } const eventToAdd = (date, i, type) => { - const duration = event.dtend.value - event.dtstart.value; - const days = duration / (1000 * 60 * 60 * 24); + // 'dtend' is null for all-day events + const { dtstart, dtend = { value: 0 } } = event; + + const days = dtend.value === 0 ? 1 : (dtend.value - dtstart.value) / (1000 * 60 * 60 * 24); const eventDate = timezone ? DateTime.fromJSDate(date, { zone: timezone }) : DateTime.fromJSDate(date); for (let j = 0; j < days; j += 1) { // See https://github.com/gethomepage/homepage/issues/2753 uid is not stable // assumption is that the event is the same if the start, end and title are all the same - const hash = simpleHash(`${event?.dtstart?.value}${event?.dtend?.value}${title}${i}${j}${type}}`); + const hash = simpleHash(`${dtstart?.value}${dtend?.value}${title}${i}${j}${type}}`); eventsToAdd[hash] = { title, date: eventDate.plus({ days: j }),