Skip to content

Build your personal knowledge base with Trilium Notes

fix(calendar): fix events spanning day boundaries without an end date

Glitch7526d9da6c8d3e7
diff --git a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts b/apps/client/src/widgets/collections/calendar/event_builder.spec.ts
index 88299e8b65..2901e1ed56 100644
--- a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts
+++ b/apps/client/src/widgets/collections/calendar/event_builder.spec.ts
@@ -199,6 +199,28 @@ describe("Recurrence", () => {
expect(events[0].end).toBeUndefined();
});
+ it("supports recurrence spanning day boundary", async () => {
+ const noteIds = buildNotes([
+ {
+ title: "Recurring Event Spanning Day Boundary",
+ "#startDate": "2025-05-05",
+ "#startTime": "23:00",
+ "#endTime": "1:00",
+ "#recurrence": "FREQ=DAILY;COUNT=3"
+ }
+ ]);
+ const events = await buildEvents(noteIds);
+
+ expect(events).toHaveLength(1);
+ expect(events[0]).toMatchObject({
+ title: "Recurring Event Spanning Day Boundary",
+ start: "2025-05-05T23:00:00",
+ duration: "02:00"
+ });
+ expect(events[0].rrule).toContain("DTSTART:20250505T230000");
+ expect(events[0].end).toBeUndefined();
+ });
+
it("supports recurrence with start and end time (duration calculated)", async () => {
const noteIds = buildNotes([
{
diff --git a/apps/client/src/widgets/collections/calendar/event_builder.ts b/apps/client/src/widgets/collections/calendar/event_builder.ts
index fd0ce3bbb2..4369e09ba0 100644
--- a/apps/client/src/widgets/collections/calendar/event_builder.ts
+++ b/apps/client/src/widgets/collections/calendar/event_builder.ts
@@ -121,6 +121,11 @@ export async function buildEvent(note: FNote, { startDate, endDate, startTime, e
}
endDate = (endTime ? `${endDate}T${endTime}:00` : endDate);
+ // If the end date is now before the start date, bump it a day forward to account for times spanning the day boundary
+ if (endDate && dayjs(endDate).isBefore(dayjs(startDate))) {
+ endDate = dayjs(endDate).add(1, "day").format("YYYY-MM-DDTHH:mm:ss");
+ }
+
const eventData: EventInput = {
id: note.noteId,
title,