From 642b45f018607441a8cfd7da2c59404b32a17db9 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Tue, 25 Oct 2022 10:23:58 +0200 Subject: [PATCH 1/2] Display events spanning more than 24h as allDay events --- src/EventModal.svelte | 5 ++++- src/calendar.js | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/EventModal.svelte b/src/EventModal.svelte index 00bc046..b386cd3 100644 --- a/src/EventModal.svelte +++ b/src/EventModal.svelte @@ -56,7 +56,10 @@ - {#if event.allDay} + {#if event.extendedProps.simAllDay} + + {dateFormat(event.start)} ({timeFormat(event.extendedProps.realStart)}) - {dateFormat(event.end)} ({timeFormat(event.extendedProps.realEnd)}) + {:else if event.allDay} {dateFormat(event.start)} - {dateFormat(event.end)} {:else} diff --git a/src/calendar.js b/src/calendar.js index e3c0b36..ca9d2d6 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -132,13 +132,29 @@ function fcEventFromjCalEvent(cal) { return function (evt) { const start = new Date(evt.dtstart) const end = new Date(evt.dtend) + + const duration = end - start // in ms + const dayMs = 24 * 3600 * 1000 + const fcEvent = { title: `${cal.short_name ?? cal.name} : ${evt.summary}`, - start: evt.dtstart, - end: evt.dtend, + start: start, + end: end, color: cal.color, textColor: invertColor(cal.color), - duration: end - start // in ms + duration: duration + } + + if (duration > dayMs - 1) { + fcEvent.allDay = true + fcEvent.simAllDay = true + + fcEvent.realStart = new Date(start) + fcEvent.realEnd = new Date(end) + + fcEvent.start.setUTCHours(0, 0, 0) + fcEvent.end.setUTCHours(23, 59, 59) + fcEvent.duration = end - start // Update the duration } fcEvent.calendar = cal.name From 32d9b4d60c601ef23df4444320aabfb94efb12a0 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Tue, 25 Oct 2022 10:38:09 +0200 Subject: [PATCH 2/2] Fix display or real allDay events --- src/calendar.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index ca9d2d6..c8ef67a 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -133,27 +133,29 @@ function fcEventFromjCalEvent(cal) { const start = new Date(evt.dtstart) const end = new Date(evt.dtend) + const allDay = !evt.dtstart.endsWith('Z') + const duration = end - start // in ms const dayMs = 24 * 3600 * 1000 const fcEvent = { title: `${cal.short_name ?? cal.name} : ${evt.summary}`, - start: start, - end: end, + start: evt.dtstart, + end: evt.dtend, color: cal.color, textColor: invertColor(cal.color), duration: duration } - if (duration > dayMs - 1) { + if (!allDay && (duration > dayMs - 1)) { fcEvent.allDay = true fcEvent.simAllDay = true fcEvent.realStart = new Date(start) fcEvent.realEnd = new Date(end) - fcEvent.start.setUTCHours(0, 0, 0) - fcEvent.end.setUTCHours(23, 59, 59) + fcEvent.start = start.setUTCHours(0, 0, 0) + fcEvent.end = end.setUTCHours(23, 59, 59) fcEvent.duration = end - start // Update the duration }