Skip to content

Commit

Permalink
fix calendar not showing events with the same name and start date bu…
Browse files Browse the repository at this point in the history
…t different calendar url (#3166)

I fixed the calendar module, which did not show calendar entries from
different calendars that share the same name and start date.

My use case: We have each office days documented in each an own
calendar. If both "Office" Calendar entries start at the same date just
one was shown

Google Calendar (each Office event in an own calendar)

![260753381-c8d5aedf-3c11-4d91-83e8-8549eb261e58](https://github.com/MichMich/MagicMirror/assets/6515818/0cb0ecbd-65bb-4ec4-b5e6-b011cb1c9c6b)

Before

![260751994-b308d549-fcb9-406e-9419-cdd2fed96dc6](https://github.com/MichMich/MagicMirror/assets/6515818/ed4d4645-0852-4e19-99ed-fec3f25d547a)

After

![260753208-3278e32b-9ca5-483a-bc6f-745cbf3964fc](https://github.com/MichMich/MagicMirror/assets/6515818/41b70843-af9f-47fc-baed-91c3c63e9acb)
  • Loading branch information
Paranoid93 authored Aug 26, 2023
1 parent 200db18 commit 2ad463b
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions modules/default/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -574,13 +575,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;
Expand Down Expand Up @@ -665,7 +667,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;
}
}
Expand Down
36 changes: 36 additions & 0 deletions tests/configs/modules/calendar/show-duplicates-in-calendar.js
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 11 additions & 0 deletions tests/e2e/modules/calendar_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
190 changes: 190 additions & 0 deletions tests/mocks/calendar_test_clone.ics
Original file line number Diff line number Diff line change
@@ -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:[email protected]
CREATED:20170310T172400Z
DESCRIPTION:
LAST-MODIFIED:20170310T172400Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:TestEvent
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

0 comments on commit 2ad463b

Please sign in to comment.