Skip to content

Commit

Permalink
add fix for sliceMultiDayEvents MagicMirrorOrg#3542
Browse files Browse the repository at this point in the history
  • Loading branch information
sdetweil committed Sep 16, 2024
1 parent 5673678 commit 126b768
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ _This release is scheduled to be released on 2024-10-01._
- [weather] Fixed issue with the UK Met Office provider following a change in their API paths and header info.
- [core] add check for node_helper loading for multiple instances of same module (#3502)
- [weather] Fixed issue for respecting unit config on broadcasted notifications
- [calendar] fixed sliceMultiDayEvents getting wrong count and displaying incorrect entries, Europe/Berlin (#3542)

## [2.28.0] - 2024-07-01

Expand Down
5 changes: 3 additions & 2 deletions modules/default/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,14 +636,15 @@ Module.register("calendar", {
* if sliceMultiDayEvents is set to true, multiday events (events exceeding at least one midnight) are sliced into days,
* otherwise, esp. in dateheaders mode it is not clear how long these events are.
*/
const maxCount = Math.ceil((event.endDate - 1 - moment(event.startDate, "x").endOf("day").format("x")) / ONE_DAY) + 1;
const maxCount = Math.round((event.endDate - 1 - moment(event.startDate, "x").endOf("day").format("x")) / ONE_DAY) + 1;
if (this.config.sliceMultiDayEvents && maxCount > 1) {
const splitEvents = [];
let midnight
= moment(event.startDate, "x")
.clone()
.startOf("day")
.add(1, "day")
.endOf("day")
.format("x");
let count = 1;
while (event.endDate > midnight) {
Expand All @@ -656,7 +657,7 @@ Module.register("calendar", {

event.startDate = midnight;
count += 1;
midnight = moment(midnight, "x").add(1, "day").format("x"); // next day
midnight = moment(midnight, "x").add(1, "day").endOf("day").format("x"); // next day
}
// Last day
event.title += ` (${count}/${maxCount})`;
Expand Down
30 changes: 30 additions & 0 deletions tests/configs/modules/calendar/sliceMultiDayEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
let config = {
timeFormat: 12,

modules: [
{
module: "calendar",
position: "bottom_bar",
config: {
hideDuplicates: false,
maximumEntries: 100,
sliceMultiDayEvents: true,
calendars: [
{
maximumEntries: 100,
url: "http://localhost:8080/tests/mocks/sliceMultiDayEvents.ics"
}
]
}
}
]
};

Date.now = () => {
return new Date("01 Sept 2024 10:38:00 GMT+2:00").valueOf();
};

/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {
module.exports = config;
}
18 changes: 18 additions & 0 deletions tests/electron/modules/calendar_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,22 @@ describe("Calendar module", () => {
expect(cnt).toBe(2);
});
});

/*
* RRULE TESTS:
* Add any tests that check rrule functionality here.
*/
describe("sliceMultiDayEvents", () => {
it("Issue #3452 split multiday in Europe", async () => {
await helpers.startApplication("tests/configs/modules/calendar/sliceMultiDayEvents.js", "01 Sept 2024 10:38:00 GMT+02:00", ["js/electron.js"], "Europe/Berlin");
expect(global.page).not.toBeNull();
const loc = await global.page.locator(".calendar .event");
const elem = loc.first();
await elem.waitFor();
expect(elem).not.toBeNull();
const cnt = await loc.count();
expect(cnt).toBe(6);
});
});

});
58 changes: 58 additions & 0 deletions tests/mocks/sliceMultiDayEvents.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Dirk Test
X-WR-TIMEZONE:Europe/Berlin
BEGIN:VEVENT
DTSTART;VALUE=DATE:20240918
DTEND;VALUE=DATE:20240919
DTSTAMP:20240916T084410Z
UID:2crbv1ijljc2kt9jclkgu5hqa0@google.com
CREATED:20240916T083831Z
LAST-MODIFIED:20240916T083831Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:1 day single
TRANSP:TRANSPARENT
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20240919
DTEND;VALUE=DATE:20240920
RRULE:FREQ=YEARLY
DTSTAMP:20240916T084410Z
UID:6gb19havnq6vp2qput51e5rmml@google.com
CREATED:20240916T083850Z
LAST-MODIFIED:20240916T083850Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:1 day repeat
TRANSP:TRANSPARENT
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20240920
DTEND;VALUE=DATE:20240922
DTSTAMP:20240916T084410Z
UID:06e9u1trbqi3jbvstvq4qqutau@google.com
CREATED:20240916T083902Z
LAST-MODIFIED:20240916T083902Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:2 day single
TRANSP:TRANSPARENT
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20240923
DTEND;VALUE=DATE:20240925
RRULE:FREQ=YEARLY
DTSTAMP:20240916T084410Z
UID:0ui78rk6hpcv8rmbb6nuonhmgg@google.com
CREATED:20240916T083919Z
LAST-MODIFIED:20240916T083919Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:2 day repeat
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR

0 comments on commit 126b768

Please sign in to comment.