From fe882bf92aae5c552e5f6e57f9a0fbadb4951cb1 Mon Sep 17 00:00:00 2001 From: jkriegshauser Date: Tue, 31 Oct 2023 23:42:47 -0700 Subject: [PATCH] Fix issue #3250: Respect deleted (excluded) calendar events (#3251) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello and thank you for wanting to contribute to the MagicMirror² project **Please make sure that you have followed these 4 rules before submitting your Pull Request:** > 1. Base your pull requests against the `develop` branch. > 2. Include these infos in the description: > > - Does the pull request solve a **related** issue? > - If so, can you reference the issue like this `Fixes #`? > - What does the pull request accomplish? Use a list if needed. > - If it includes major visual changes please add screenshots. > > 3. Please run `npm run lint:prettier` before submitting so that > style issues are fixed. > 4. Don't forget to add an entry about your changes to > the CHANGELOG.md file. **Note**: Sometimes the development moves very fast. It is highly recommended that you update your branch of `develop` before creating a pull request to send us your changes. This makes everyone's lives easier (including yours) and helps us out on the development team. Thanks again and have a nice day! --- .prettierignore | 3 ++ CHANGELOG.md | 1 + .../default/calendar/calendarfetcherutils.js | 12 ++++--- tests/configs/modules/calendar/exdate.js | 36 +++++++++++++++++++ tests/e2e/modules/calendar_spec.js | 11 ++++++ tests/mocks/calendar_test_exdate.ics | 34 ++++++++++++++++++ 6 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 tests/configs/modules/calendar/exdate.js create mode 100644 tests/mocks/calendar_test_exdate.ics diff --git a/.prettierignore b/.prettierignore index b92f2166..b115c755 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,6 @@ +.eslintignore +.prettierignore /config /coverage package-lock.json +**.ics diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a170d33..7be7d3d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ _This release is scheduled to be released on 2024-01-01._ - Fix newsfeed module for feeds using "a10:updated" tag (#3238) - Fix issue template (#3167) - Fix for failing unit test (#3254) +- Fix calendar events sometimes not respecting deleted events (#3250) ## [2.25.0] - 2023-10-01 diff --git a/modules/default/calendar/calendarfetcherutils.js b/modules/default/calendar/calendarfetcherutils.js index 34cc2578..3a90ae7e 100644 --- a/modules/default/calendar/calendarfetcherutils.js +++ b/modules/default/calendar/calendarfetcherutils.js @@ -305,11 +305,6 @@ const CalendarFetcherUtils = { // Loop through the set of date entries to see which recurrences should be added to our event list. for (let d in dates) { let date = dates[d]; - // Remove the time information of each date by using its substring, using the following method: - // .toISOString().substring(0,10). - // since the date is given as ISOString with YYYY-MM-DDTHH:MM:SS.SSSZ - // (see https://momentjs.com/docs/#/displaying/as-iso-string/). - const dateKey = date.toISOString().substring(0, 10); let curEvent = event; let showRecurrence = true; @@ -402,6 +397,13 @@ const CalendarFetcherUtils = { let adjustDays = CalendarFetcherUtils.calculateTimezoneAdjustment(event, date); + // Remove the time information of each date by using its substring, using the following method: + // .toISOString().substring(0,10). + // since the date is given as ISOString with YYYY-MM-DDTHH:MM:SS.SSSZ + // (see https://momentjs.com/docs/#/displaying/as-iso-string/). + // This must be done after `date` is adjusted + const dateKey = date.toISOString().substring(0, 10); + // For each date that we're checking, it's possible that there is a recurrence override for that one day. if (curEvent.recurrences !== undefined && curEvent.recurrences[dateKey] !== undefined) { // We found an override, so for this recurrence, use a potentially different title, start date, and duration. diff --git a/tests/configs/modules/calendar/exdate.js b/tests/configs/modules/calendar/exdate.js new file mode 100644 index 00000000..574b24fe --- /dev/null +++ b/tests/configs/modules/calendar/exdate.js @@ -0,0 +1,36 @@ +/* MagicMirror² Test calendar exdate + * + * By jkriegshauser + * MIT Licensed. + * + * NOTE: calendar_test_exdate.ics has exdate entries for the next 20 years, but without some + * way to set a debug date for tests, this test may become flaky on specific days (i.e. could + * not test easily on leap-years, the BYDAY specified in exdate, etc.) or when the 20 years + * elapses if this project is still in active development ;) + * See issue #3250 + */ +let config = { + timeFormat: 12, + + modules: [ + { + module: "calendar", + position: "bottom_bar", + config: { + maximumEntries: 100, + calendars: [ + { + maximumEntries: 100, + maximumNumberOfDays: 364, + url: "http://localhost:8080/tests/mocks/calendar_test_exdate.ics" + } + ] + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 299bdf66..39855288 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -84,6 +84,17 @@ describe("Calendar module", () => { }); }); + describe("exdate check", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/calendar/exdate.js"); + await helpers.getDocument(); + }); + + it("should show the recurring event 51 times (excluded once) in a 364-day (inclusive) period", async () => { + await testElementLength(".calendar .event", 51); + }); + }); + describe("Events from multiple calendars", () => { beforeAll(async () => { await helpers.startApplication("tests/configs/modules/calendar/show-duplicates-in-calendar.js"); diff --git a/tests/mocks/calendar_test_exdate.ics b/tests/mocks/calendar_test_exdate.ics new file mode 100644 index 00000000..8f1f8b9f --- /dev/null +++ b/tests/mocks/calendar_test_exdate.ics @@ -0,0 +1,34 @@ +BEGIN:VEVENT +DTSTART;TZID=UTC:20231025T181000 +DTEND;TZID=UTC:20231025T195000 +RRULE:FREQ=WEEKLY;BYDAY=WE +EXDATE;TZID=UTC:20231101T181000 +EXDATE;TZID=UTC:20241030T181000 +EXDATE;TZID=UTC:20251029T181000 +EXDATE;TZID=UTC:20261028T181000 +EXDATE;TZID=UTC:20271027T181000 +EXDATE;TZID=UTC:20281025T181000 +EXDATE;TZID=UTC:20291024T181000 +EXDATE;TZID=UTC:20301023T181000 +EXDATE;TZID=UTC:20311022T181000 +EXDATE;TZID=UTC:20321020T181000 +EXDATE;TZID=UTC:20331019T181000 +EXDATE;TZID=UTC:20341018T181000 +EXDATE;TZID=UTC:20351017T181000 +EXDATE;TZID=UTC:20361015T181000 +EXDATE;TZID=UTC:20371014T181000 +EXDATE;TZID=UTC:20381013T181000 +EXDATE;TZID=UTC:20391012T181000 +EXDATE;TZID=UTC:20401010T181000 +EXDATE;TZID=UTC:20411009T181000 +EXDATE;TZID=UTC:20421008T181000 +EXDATE;TZID=UTC:20431007T181000 +DTSTAMP:20231025T233434Z +UID:sdflbkasuhdb5fkauglkb@google.com +CREATED:20230306T193128Z +LAST-MODIFIED:20231024T222515Z +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:My Event +TRANSP:OPAQUE +END:VEVENT