From 7d8b6e2a50f67c0cf334f7ecb7f49b9fe3146f8a Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 10 Feb 2024 12:07:33 -0800 Subject: [PATCH] Refactor all-day events logic --- src/widgets/calendar/integrations/ical.jsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/widgets/calendar/integrations/ical.jsx b/src/widgets/calendar/integrations/ical.jsx index 079ee9ff..05d059c7 100644 --- a/src/widgets/calendar/integrations/ical.jsx +++ b/src/widgets/calendar/integrations/ical.jsx @@ -52,12 +52,10 @@ export default function Integration({ config, params, setEvents, hideErrors, tim } const eventToAdd = (date, i, type) => { - // When the 'dtend' is not defined (one-day all-day event), 'dtend' should be the same as 'dtstart'. - const { dtstart } = event; - const dtend = 'dtend' in event ? event.dtend : dtstart; + // 'dtend' is null for all-day events + const { dtstart, dtend = { value: 0 } } = event; - const duration = dtend.value - dtstart.value; - const days = duration === 0 ? 1 : duration / (1000 * 60 * 60 * 24); + 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);