diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e38eb2909..4d00226178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ _This release is scheduled to be released on 2023-10-01._ ### Added - Added UV Index support to OpenWeatherMap +- Added 'hideDuplicates' flag to the calendar module ### Removed diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 3343d347ad..0cbc72d4c1 100644 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -39,6 +39,7 @@ Module.register("calendar", { hidePrivate: false, hideOngoing: false, hideTime: false, + hideDuplicates: true, showTimeToday: false, colored: false, customEvents: [], // Array of {keyword: "", symbol: "", color: ""} where Keyword is a regexp and symbol/color are to be applied for matched @@ -571,13 +572,14 @@ Module.register("calendar", { if (this.config.hideOngoing && event.startDate < now) { continue; } - if (this.listContainsEvent(events, event)) { + if (this.config.hideDuplicates && this.listContainsEvent(events, event)) { continue; } if (--remainingEntries < 0) { break; } } + event.url = calendarUrl; event.today = event.startDate >= today && event.startDate < today + ONE_DAY; event.dayBeforeYesterday = event.startDate >= today - ONE_DAY * 2 && event.startDate < today - ONE_DAY; @@ -662,7 +664,7 @@ Module.register("calendar", { listContainsEvent: function (eventList, event) { for (const evt of eventList) { - if (evt.title === event.title && parseInt(evt.startDate) === parseInt(event.startDate)) { + if (evt.title === event.title && parseInt(evt.startDate) === parseInt(event.startDate) && parseInt(evt.endDate) === parseInt(event.endDate)) { return true; } } diff --git a/tests/configs/modules/calendar/show-duplicates-in-calendar.js b/tests/configs/modules/calendar/show-duplicates-in-calendar.js new file mode 100644 index 0000000000..89fb8eb93e --- /dev/null +++ b/tests/configs/modules/calendar/show-duplicates-in-calendar.js @@ -0,0 +1,36 @@ +/* MagicMirror² Test config for multiple calendar events having the same name and start date/time + * + * By Paranoid93 https://github.com/Paranoid93/ + * MIT Licensed. + */ +let config = { + timeFormat: 12, + + modules: [ + { + module: "calendar", + position: "bottom_bar", + config: { + maximumEntries: 30, + hideDuplicates: false, + calendars: [ + { + maximumEntries: 15, + maximumNumberOfDays: 10000, + url: "http://localhost:8080/tests/mocks/calendar_test.ics" // contains 11 events + }, + { + maximumEntries: 15, + maximumNumberOfDays: 10000, + url: "http://localhost:8080/tests/mocks/calendar_test_clone.ics" // clone of upper calendar + } + ] + } + } + ] +}; + +/*************** 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 6932f124fa..fc9c1a174e 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -80,6 +80,17 @@ describe("Calendar module", () => { }); }); + describe("Events from multiple calendars", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/calendar/show-duplicates-in-calendar.js"); + await helpers.getDocument(); + }); + + it("should show multiple events with the same title and start time from different calendars", async () => { + await testElementLength(".calendar .event", 22); + }); + }); + process.setMaxListeners(0); for (let i = -12; i < 12; i++) { describe("Recurring event per timezone", () => { diff --git a/tests/mocks/calendar_test_clone.ics b/tests/mocks/calendar_test_clone.ics new file mode 100644 index 0000000000..1b5277153d --- /dev/null +++ b/tests/mocks/calendar_test_clone.ics @@ -0,0 +1,190 @@ +BEGIN:VCALENDAR +PRODID:-//Google Inc//Google Calendar 70.9054//EN +VERSION:2.0 +CALSCALE:GREGORIAN +METHOD:PUBLISH +X-WR-CALNAME:MagicMirrorTest +X-WR-TIMEZONE:America/Santiago +X-WR-CALDESC:Testing propose MagicMirror +BEGIN:VTIMEZONE +TZID:America/Santiago +X-LIC-LOCATION:America/Santiago +BEGIN:STANDARD +TZOFFSETFROM:-0300 +TZOFFSETTO:-0400 +TZNAME:-04 +DTSTART:19700510T000000 +RDATE:19700510T030000 +RDATE:19710509T030000 +RDATE:19720514T030000 +RDATE:19730513T030000 +RDATE:19740512T030000 +RDATE:19750511T030000 +RDATE:19760509T030000 +RDATE:19770515T030000 +RDATE:19780514T030000 +RDATE:19790513T030000 +RDATE:19800511T030000 +RDATE:19810510T030000 +RDATE:19820509T030000 +RDATE:19830515T030000 +RDATE:19840513T030000 +RDATE:19850512T030000 +RDATE:19860511T030000 +RDATE:19870510T030000 +RDATE:19880515T030000 +RDATE:19890514T030000 +RDATE:19900513T030000 +RDATE:19910512T030000 +RDATE:19920510T030000 +RDATE:19930509T030000 +RDATE:19940515T030000 +RDATE:19950514T030000 +RDATE:19960512T030000 +RDATE:19970511T030000 +RDATE:19980510T030000 +RDATE:19990509T030000 +RDATE:20000514T030000 +RDATE:20010513T030000 +RDATE:20020512T030000 +RDATE:20030511T030000 +RDATE:20040509T030000 +RDATE:20050515T030000 +RDATE:20060514T030000 +RDATE:20070513T030000 +RDATE:20080511T030000 +RDATE:20090510T030000 +RDATE:20100509T030000 +RDATE:20110515T030000 +RDATE:20120513T030000 +RDATE:20130512T030000 +RDATE:20140511T030000 +RDATE:20150510T030000 +RDATE:20160515T030000 +RDATE:20170514T030000 +RDATE:20180513T030000 +RDATE:20190512T030000 +RDATE:20200510T030000 +RDATE:20210509T030000 +RDATE:20220515T030000 +RDATE:20230514T030000 +RDATE:20240512T030000 +RDATE:20250511T030000 +RDATE:20260510T030000 +RDATE:20270509T030000 +RDATE:20280514T030000 +RDATE:20290513T030000 +RDATE:20300512T030000 +RDATE:20310511T030000 +RDATE:20320509T030000 +RDATE:20330515T030000 +RDATE:20340514T030000 +RDATE:20350513T030000 +RDATE:20360511T030000 +RDATE:20370510T030000 +END:STANDARD +BEGIN:STANDARD +TZOFFSETFROM:-0300 +TZOFFSETTO:-0400 +TZNAME:-04 +DTSTART:20380509T000000 +RRULE:FREQ=YEARLY;BYMONTH=5;BYDAY=2SU +END:STANDARD +BEGIN:DAYLIGHT +TZOFFSETFROM:-0400 +TZOFFSETTO:-0300 +TZNAME:-03 +DTSTART:19700809T000000 +RDATE:19700809T040000 +RDATE:19710815T040000 +RDATE:19720813T040000 +RDATE:19730812T040000 +RDATE:19740811T040000 +RDATE:19750810T040000 +RDATE:19760815T040000 +RDATE:19770814T040000 +RDATE:19780813T040000 +RDATE:19790812T040000 +RDATE:19800810T040000 +RDATE:19810809T040000 +RDATE:19820815T040000 +RDATE:19830814T040000 +RDATE:19840812T040000 +RDATE:19850811T040000 +RDATE:19860810T040000 +RDATE:19870809T040000 +RDATE:19880814T040000 +RDATE:19890813T040000 +RDATE:19900812T040000 +RDATE:19910811T040000 +RDATE:19920809T040000 +RDATE:19930815T040000 +RDATE:19940814T040000 +RDATE:19950813T040000 +RDATE:19960811T040000 +RDATE:19970810T040000 +RDATE:19980809T040000 +RDATE:19990815T040000 +RDATE:20000813T040000 +RDATE:20010812T040000 +RDATE:20020811T040000 +RDATE:20030810T040000 +RDATE:20040815T040000 +RDATE:20050814T040000 +RDATE:20060813T040000 +RDATE:20070812T040000 +RDATE:20080810T040000 +RDATE:20090809T040000 +RDATE:20100815T040000 +RDATE:20110814T040000 +RDATE:20120812T040000 +RDATE:20130811T040000 +RDATE:20140810T040000 +RDATE:20150809T040000 +RDATE:20160814T040000 +RDATE:20170813T040000 +RDATE:20180812T040000 +RDATE:20190811T040000 +RDATE:20200809T040000 +RDATE:20210815T040000 +RDATE:20220814T040000 +RDATE:20230813T040000 +RDATE:20240811T040000 +RDATE:20250810T040000 +RDATE:20260809T040000 +RDATE:20270815T040000 +RDATE:20280813T040000 +RDATE:20290812T040000 +RDATE:20300811T040000 +RDATE:20310810T040000 +RDATE:20320815T040000 +RDATE:20330814T040000 +RDATE:20340813T040000 +RDATE:20350812T040000 +RDATE:20360810T040000 +RDATE:20370809T040000 +END:DAYLIGHT +BEGIN:DAYLIGHT +TZOFFSETFROM:-0400 +TZOFFSETTO:-0300 +TZNAME:-03 +DTSTART:20380815T000000 +RRULE:FREQ=YEARLY;BYMONTH=8;BYDAY=2SU +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +DTSTART;TZID=America/Santiago:20170309T100000 +DTEND;TZID=America/Santiago:20170309T110000 +RRULE:FREQ=MONTHLY;INTERVAL=30;BYMONTHDAY=9 +DTSTAMP:20170310T172720Z +UID:80rl9kuu5bq49gme99eklov27k@google.com +CREATED:20170310T172400Z +DESCRIPTION: +LAST-MODIFIED:20170310T172400Z +LOCATION: +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:TestEvent +TRANSP:OPAQUE +END:VEVENT +END:VCALENDAR