Skip to content

Commit 99e782a

Browse files
fix: past events not showing
1 parent 79afa6c commit 99e782a

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

MMM-GoogleCalendar.js

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,37 @@ Module.register("MMM-GoogleCalendar", {
520520
return wrapper;
521521
},
522522

523+
/**
524+
* Filter out events according to the calendar config
525+
* @param {object} event the google calendar event
526+
* @param {array} eventsList the array of event
527+
* @returns {boolean}
528+
*/
529+
filterEvent: function(event, eventsList) {
530+
531+
// check if event name is in the excluded list
532+
if (this.config.excludedEvents?.length && this.config.excludedEvents.includes(event.summary)) {
533+
Log.debug(`Event ${event.id} filtered due to excludedEvents settings`);
534+
return true
535+
}
536+
537+
if (this.config.hidePrivate && ['private', 'confidential'].includes(event.visibility?.toLowerCase())) {
538+
return true;
539+
}
540+
541+
if (this.config.hideDuplicates && this.listContainsEvent(eventsList, event)) {
542+
return true;
543+
}
544+
545+
const now = new Date();
546+
547+
if (this.config.hideOngoing && event.startDate < now && event.endDate > now) {
548+
return true;
549+
}
550+
551+
return false;
552+
},
553+
523554
fetchCalendars: function () {
524555
this.config.calendars.forEach((calendar) => {
525556
if (!calendar.calendarID) {
@@ -628,33 +659,23 @@ Module.register("MMM-GoogleCalendar", {
628659
for (const e in calendar) {
629660
const event = JSON.parse(JSON.stringify(calendar[e])); // clone object
630661

631-
// check if event is to be excluded
632-
if (this.config.excludedEvents.includes(event.summary)) {
633-
continue;
634-
}
635-
636662
// added props
637663
event.calendarID = calendarID;
638664
event.endDate = this.extractCalendarDate(event.end);
639665
event.startDate = this.extractCalendarDate(event.start);
640666

641-
if (event.endDate < now) {
642-
continue;
643-
}
644-
if (this.config.hidePrivate) {
645-
if (event.visibility === "PRIVATE") {
646-
// do not add the current event, skip it
647-
continue;
648-
}
649-
}
650-
if (this.config.hideOngoing) {
651-
if (event.endDate < now) {
652-
continue;
653-
}
654-
}
655-
if (this.config.hideDuplicates && this.listContainsEvent(events, event)) {
656-
continue;
657-
}
667+
// check if event is to be excluded
668+
if (this.filterEvent(event, events)) {
669+
continue;
670+
}
671+
672+
// exclude if events are duplicate - this check is outside filterEvent fn
673+
// to prevent overloading on passing params
674+
if (this.config.hideDuplicates && this.listContainsEvent(events, event)) {
675+
continue;
676+
}
677+
678+
658679
event.url = event.htmlLink;
659680
event.today =
660681
event.startDate >= today &&
@@ -1060,6 +1081,11 @@ Module.register("MMM-GoogleCalendar", {
10601081
let endDate = event.end?.date ?? event.end?.dateTime;
10611082
event.startDate = (startDate) ? moment(startDate).valueOf() : null;
10621083
event.endDate = (endDate) ? moment(endDate).valueOf() : null;
1084+
1085+
if (this.config.broadcastEvents && !this.config.broadcastPastEvents && event.endDate < now) {
1086+
continue
1087+
}
1088+
10631089
eventList.push(event);
10641090
}
10651091
}

node_helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ module.exports = NodeHelper.create({
216216
this.calendarService.events.list(
217217
{
218218
calendarId: calendarID,
219-
timeMin: (new Date(new Date().setDate(new Date().getDate() - pastDaysCount))).toISOString(),
220-
maxResults: maximumEntries,
219+
timeMin: (new Date(new Date().setDate(new Date().getDate() - pastDaysCount))).toISOString(), // Lower bound (exclusive) for an event's end time to filter by
220+
maxResults: maximumEntries, // Maximum number of events returned
221221
singleEvents: true,
222222
orderBy: "startTime"
223223
},

0 commit comments

Comments
 (0)