diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d4ecd61..4d7b3dcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ _This release is scheduled to be released on 2022-04-01._ - update `helmet` to v5, use defaults of v4. - updates Font Awesome css class to new default style (fixes #2768) - replaced deprecated modules `currentweather` and `weatherforecast` with dummy modules only displaying that they have to be replaced. +- include all calendar events from the configured date range when broadcasting. ### Fixed diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index c38f7a6e..5d6ab0b4 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -164,7 +164,7 @@ Module.register("calendar", { const oneHour = oneMinute * 60; const oneDay = oneHour * 24; - const events = this.createEventList(); + const events = this.createEventList(true); const wrapper = document.createElement("table"); wrapper.className = this.config.tableClass; @@ -477,9 +477,10 @@ Module.register("calendar", { /** * Creates the sorted list of all events. * + * @param {boolean} forDisplay Whether to filter returned events for display. * @returns {object[]} Array with events. */ - createEventList: function () { + createEventList: function (forDisplay) { const now = new Date(); const today = moment().startOf("day"); const future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate(); @@ -490,7 +491,7 @@ Module.register("calendar", { for (const e in calendar) { const event = JSON.parse(JSON.stringify(calendar[e])); // clone object - if (event.endDate < now) { + if (event.endDate < now && forDisplay) { continue; } if (this.config.hidePrivate) { @@ -499,7 +500,7 @@ Module.register("calendar", { continue; } } - if (this.config.hideOngoing) { + if (this.config.hideOngoing && forDisplay) { if (event.startDate < now) { continue; } @@ -548,6 +549,10 @@ Module.register("calendar", { return a.startDate - b.startDate; }); + if (!forDisplay) { + return events; + } + // Limit the number of days displayed // If limitDays is set > 0, limit display to that number of days if (this.config.limitDays > 0) { @@ -835,22 +840,14 @@ Module.register("calendar", { * The all events available in one array, sorted on startdate. */ broadcastEvents: function () { - const eventList = []; - for (const url in this.calendarData) { - for (const ev of this.calendarData[url]) { - const event = cloneObject(ev); - event.symbol = this.symbolsForEvent(event); - event.calendarName = this.calendarNameForUrl(url); - event.color = this.colorForUrl(url); - delete event.url; - eventList.push(event); - } + const eventList = this.createEventList(false); + for (const event of eventList) { + event.symbol = this.symbolsForEvent(event); + event.calendarName = this.calendarNameForUrl(event.url); + event.color = this.colorForUrl(event.url); + delete event.url; } - eventList.sort(function (a, b) { - return a.startDate - b.startDate; - }); - this.sendNotification("CALENDAR_EVENTS", eventList); } }); diff --git a/modules/default/calendar/calendarutils.js b/modules/default/calendar/calendarutils.js index a3bfaeab..f7409b5c 100644 --- a/modules/default/calendar/calendarutils.js +++ b/modules/default/calendar/calendarutils.js @@ -498,23 +498,7 @@ const CalendarUtils = { return a.startDate - b.startDate; }); - // include up to maximumEntries current or upcoming events - // If past events should be included, include all past events - const now = moment(); - let entries = 0; - let events = []; - for (let ne of newEvents) { - if (moment(ne.endDate, "x").isBefore(now)) { - if (config.includePastEvents) events.push(ne); - continue; - } - entries++; - // If max events has been saved, skip the rest - if (entries > config.maximumEntries) break; - events.push(ne); - } - - return events; + return newEvents; }, /**