add fix for sliceMultiDayEvents (#3543)

sliceMultiDayEvents occasionally gets the number of events wrong and
produces too many rows

Math.ceil() rounds up over 1.04 so we get an abnormal count

then the calcs for the midnight loop control used different moment()
functions, producing different results

fixes #3542
This commit is contained in:
sam detweiler 2024-09-17 01:01:49 -05:00 committed by GitHub
parent 0faefd109a
commit ea3a323581
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 110 additions and 2 deletions

View File

@ -30,6 +30,7 @@ _This release is scheduled to be released on 2024-10-01._
- [core] add check for node_helper loading for multiple instances of same module (#3502) - [core] add check for node_helper loading for multiple instances of same module (#3502)
- [weather] Fixed issue for respecting unit config on broadcasted notifications - [weather] Fixed issue for respecting unit config on broadcasted notifications
- [tests] Fixes calendar test by moving it from e2e to electron with fixed date (#3532) - [tests] Fixes calendar test by moving it from e2e to electron with fixed date (#3532)
- [calendar] fixed sliceMultiDayEvents getting wrong count and displaying incorrect entries, Europe/Berlin (#3542)
## [2.28.0] - 2024-07-01 ## [2.28.0] - 2024-07-01

View File

@ -636,7 +636,7 @@ Module.register("calendar", {
* if sliceMultiDayEvents is set to true, multiday events (events exceeding at least one midnight) are sliced into days, * 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. * 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) { if (this.config.sliceMultiDayEvents && maxCount > 1) {
const splitEvents = []; const splitEvents = [];
let midnight let midnight
@ -644,6 +644,7 @@ Module.register("calendar", {
.clone() .clone()
.startOf("day") .startOf("day")
.add(1, "day") .add(1, "day")
.endOf("day")
.format("x"); .format("x");
let count = 1; let count = 1;
while (event.endDate > midnight) { while (event.endDate > midnight) {
@ -656,7 +657,7 @@ Module.register("calendar", {
event.startDate = midnight; event.startDate = midnight;
count += 1; 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 // Last day
event.title += ` (${count}/${maxCount})`; event.title += ` (${count}/${maxCount})`;

View File

@ -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;
}

View File

@ -129,4 +129,22 @@ describe("Calendar module", () => {
await expect(doTestCount()).resolves.toBe(2); await expect(doTestCount()).resolves.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);
});
});
}); });

View File

@ -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