From ffcd8dd1208f5fcfb64df2536bffbaf32b076864 Mon Sep 17 00:00:00 2001 From: ago1776 Date: Fri, 17 Jul 2026 11:27:50 +0200 Subject: [PATCH] fix(calendar): sliced multi-day events start at 00:00, not 23:59 With `sliceMultiDayEvents: true`, every slice after the first was given the following day's `endOf("day")` (23:59:59.999) as its `startDate`, so slices 2..n rendered a start time of 23:59 instead of the next day's 00:00. Set the next slice's start to `startOf("day")` of that day. Adds an electron regression test (scenario `slice_multiday_timed_start_midnight` with a timed event spanning several midnights): every rendered slice time cell must contain a 00:00 start and never 23:59. Fails without the fix. Closes #4206 Co-Authored-By: Claude Opus 4.8 (cherry picked from commit 890db2bb44a357bc977819b85634c7bcde42ada4) --- defaultmodules/calendar/calendar.js | 2 +- .../calendar/calendarShowEndConfigs.js | 26 +++++++++++++++++++ tests/electron/modules/calendar_spec.js | 14 ++++++++++ .../calendar_test_slice_multiday_timed.ics | 16 ++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/mocks/calendar_test_slice_multiday_timed.ics diff --git a/defaultmodules/calendar/calendar.js b/defaultmodules/calendar/calendar.js index 9451a164a8..8930a96531 100644 --- a/defaultmodules/calendar/calendar.js +++ b/defaultmodules/calendar/calendar.js @@ -531,7 +531,7 @@ Module.register("calendar", { thisEvent.title += ` (${count}/${maxCount})`; splitEvents.push(thisEvent); - event.startDate = midnight.format("x"); + event.startDate = midnight.clone().startOf("day").format("x"); // start next slice at 00:00, not 23:59 count += 1; midnight = midnight.clone().add(1, "day").endOf("day"); // next day } diff --git a/tests/configs/modules/calendar/calendarShowEndConfigs.js b/tests/configs/modules/calendar/calendarShowEndConfigs.js index 129ad97388..b92b38482a 100644 --- a/tests/configs/modules/calendar/calendarShowEndConfigs.js +++ b/tests/configs/modules/calendar/calendarShowEndConfigs.js @@ -347,6 +347,32 @@ const calendarShowEndConfigs = { } } ] + }, + slice_multiday_timed_start_midnight: { + address: "0.0.0.0", + ipWhitelist: [], + timeFormat: 24, + modules: [ + { + module: "calendar", + position: "bottom_bar", + config: { + fade: false, + urgency: 0, + dateFormat: "Do.MMM, HH:mm", + fullDayEventDateFormat: "Do.MMM", + timeFormat: "absolute", + getRelative: 0, + sliceMultiDayEvents: true, + calendars: [ + { + maximumEntries: 100, + url: "http://localhost:8080/tests/mocks/calendar_test_slice_multiday_timed.ics" + } + ] + } + } + ] } }; diff --git a/tests/electron/modules/calendar_spec.js b/tests/electron/modules/calendar_spec.js index 655e7e59c8..dbee802006 100644 --- a/tests/electron/modules/calendar_spec.js +++ b/tests/electron/modules/calendar_spec.js @@ -181,6 +181,20 @@ describe("Calendar module", () => { }); }); + describe("sliceMultiDayEvents slice start time", () => { + it("sliced sub-events start at 00:00, not 23:59", async () => { + // Timed event Fri 25 Oct 12:00 -> Mon 28 Oct 08:00 (UTC) is sliced across + // several midnights. Every slice after the first must start at 00:00 of its + // day. Regression for the bug where they started at 23:59 instead. + await startCalendarShowEndScenario("slice_multiday_timed_start_midnight", "25 Oct 2024 06:00:00 GMT", "GMT"); + const firstTimeCell = global.page.locator(".calendar .event .time").locator(`nth=${first}`); + await firstTimeCell.waitFor({ state: "visible" }); + const times = await global.page.locator(".calendar .event .time").allTextContents(); + expect(times.some((time) => time.includes("00:00"))).toBe(true); + expect(times.every((time) => !time.includes("23:59"))).toBe(true); + }); + }); + describe("germany timezone", () => { it("Issue #unknown fullday timezone East of UTC edge", async () => { await helpers.startApplication("tests/configs/modules/calendar/germany_at_end_of_day_repeating.js", "01 Oct 2024 10:38:00 GMT+02:00", [], "Europe/Berlin"); diff --git a/tests/mocks/calendar_test_slice_multiday_timed.ics b/tests/mocks/calendar_test_slice_multiday_timed.ics new file mode 100644 index 0000000000..b6079a1b1c --- /dev/null +++ b/tests/mocks/calendar_test_slice_multiday_timed.ics @@ -0,0 +1,16 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//MagicMirror//slice regression//EN +CALSCALE:GREGORIAN +METHOD:PUBLISH +BEGIN:VEVENT +DTSTART:20241025T120000Z +DTEND:20241028T080000Z +DTSTAMP:20241024T153358Z +UID:slice-midnight-regression@magicmirror.test +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:Timed multi-day slice +TRANSP:OPAQUE +END:VEVENT +END:VCALENDAR