Skip to content

Build your personal knowledge base with Trilium Notes

feat(calendar): let a timed event span several days from the popups

Elian Doran2ace5c16ea22
diff --git a/apps/client/src/widgets/collections/calendar/EventDatesEditor.spec.tsx b/apps/client/src/widgets/collections/calendar/EventDatesEditor.spec.tsx
index b5aa1864cd..0b0a5bb115 100644
--- a/apps/client/src/widgets/collections/calendar/EventDatesEditor.spec.tsx
+++ b/apps/client/src/widgets/collections/calendar/EventDatesEditor.spec.tsx
@@ -68,7 +68,8 @@ describe("EventDatesEditor", () => {
mount(buildNote({ title: "Meeting", "#startDate": "2026-06-05", "#startTime": "13:00", "#endTime": "14:30" }));
expect(addTimeButton()).toBeNull();
- expect(dateInputs()).toHaveLength(1);
+ // A timed event has an end date too; empty, it ends on the day it starts.
+ expect([ ...dateInputs() ].map((input) => input.value)).toEqual([ "2026-06-05", "" ]);
expect(timeInputs()).toHaveLength(2);
expect(timeInputs()[0].closest(".calendar-event-row")?.contains(removeTimeButton())).toBe(true);
expect(timeInputs()[0].value).toBe("13:00");
@@ -77,7 +78,7 @@ describe("EventDatesEditor", () => {
expect(timeInputs()[0].closest(".calendar-event-row")?.querySelector(".calendar-event-duration")).not.toBeNull();
});
- it("adding a time gives the day hours to edit and lets a span of days go", () => {
+ it("adding a time gives the days hours to edit and keeps the span of days", () => {
const note = buildNote({ title: "Fair", "#startDate": "2026-06-05", "#endDate": "2026-06-07" });
mount(note);
@@ -85,11 +86,25 @@ describe("EventDatesEditor", () => {
expect(setLabel).toHaveBeenCalledWith(note.noteId, "startTime", "09:00");
expect(setLabel).toHaveBeenCalledWith(note.noteId, "endTime", "10:00");
- expect(removeLabel).toHaveBeenCalledWith(note, "endDate");
+ expect(removeLabel).not.toHaveBeenCalled();
// The fields answer the press at once, ahead of the labels echoing back.
expect(timeInputs()).toHaveLength(2);
expect(document.activeElement).toBe(timeInputs()[0]);
- expect(dateInputs()).toHaveLength(1);
+ expect(dateInputs()).toHaveLength(2);
+ });
+
+ it("shows and edits the end date of a timed event that spans several days", () => {
+ const note = buildNote({
+ title: "Night shift", "#startDate": "2026-06-05", "#endDate": "2026-06-06",
+ "#startTime": "22:00", "#endTime": "01:00"
+ });
+ mount(note);
+
+ expect([ ...dateInputs() ].map((input) => input.value)).toEqual([ "2026-06-05", "2026-06-06" ]);
+ expect(duration()).toBe("calendar_view.duration_hours|3");
+
+ commitValue(dateInputs()[1], "2026-06-07");
+ expect(setLabel).toHaveBeenCalledWith(note.noteId, "endDate", "2026-06-07");
});
it("removing the time takes the hours off and keeps the dates", () => {
diff --git a/apps/client/src/widgets/collections/calendar/EventDatesEditor.tsx b/apps/client/src/widgets/collections/calendar/EventDatesEditor.tsx
index 126074872f..affdd98c6d 100644
--- a/apps/client/src/widgets/collections/calendar/EventDatesEditor.tsx
+++ b/apps/client/src/widgets/collections/calendar/EventDatesEditor.tsx
@@ -54,11 +54,10 @@ export default function EventDatesEditor({ note, repeats }: {
}
/**
- * The date and time rows of an event, shared by the event popover and the new-event popup. Two
- * shapes, told apart by whether the event has hours: a whole-day event is a span of days — a start
- * date and, where it runs longer, an end date — while a timed one is a single day and the hours
- * within it, with their duration. Fields commit as they are left, and hand the whole edited event
- * to `onChange`.
+ * The date and time rows of an event, shared by the event popover and the new-event popup. The
+ * date row holds a start date and, where the event runs longer than a day, an end date; the time
+ * row holds the hours and their duration, or the button to add them for an all-day event. Fields
+ * commit as they are left, and hand the whole edited event to `onChange`.
*/
export function EventDatesFields({ value, allDay, onChange }: {
value: EventDraft;
@@ -81,18 +80,16 @@ export function EventDatesFields({ value, allDay, onChange }: {
onCommit={(date) => date && onChange({ ...value, startDate: date })}
inputProps={{ className: "form-control", "aria-label": t("calendar.dates.start_date") }}
/>
- {allDay && <>
- <span className="calendar-event-row-separator" aria-hidden="true">–</span>
- <LabelValueInput
- labelType="date"
- value={endDate ?? ""}
- commitOn="blur"
- // Emptied, the event is a single day: the label goes rather than
- // staying blank, which is how the builder reads a day-long event.
- onCommit={(date) => onChange({ ...value, endDate: date || null })}
- inputProps={{ className: "form-control", "aria-label": t("calendar.dates.end_date") }}
- />
- </>}
+ <span className="calendar-event-row-separator" aria-hidden="true">–</span>
+ <LabelValueInput
+ labelType="date"
+ value={endDate ?? ""}
+ commitOn="blur"
+ // Emptied, the event ends on the day it starts: the label goes rather than
+ // staying blank, which is how the builder reads a single-day event.
+ onCommit={(date) => onChange({ ...value, endDate: date || null })}
+ inputProps={{ className: "form-control", "aria-label": t("calendar.dates.end_date") }}
+ />
</EventRow>
<EventTimeRow
diff --git a/apps/client/src/widgets/collections/calendar/GhostPopover.spec.tsx b/apps/client/src/widgets/collections/calendar/GhostPopover.spec.tsx
index e1f721c69f..0c09d31c0c 100644
--- a/apps/client/src/widgets/collections/calendar/GhostPopover.spec.tsx
+++ b/apps/client/src/widgets/collections/calendar/GhostPopover.spec.tsx
@@ -135,7 +135,7 @@ describe("GhostPopover", () => {
expect(end.value).toBe("10:00");
expect(duration()).toBe("calendar_view.duration_hours|1");
- expect(dateInputs()).toHaveLength(1);
+ expect(dateInputs()).toHaveLength(2);
commitValue(start, "14:00");
commitValue(timeInputs()[1], "15:30");
expect(duration()).toBe("calendar_view.duration_hours_minutes|1|30");
@@ -143,7 +143,7 @@ describe("GhostPopover", () => {
await act(async () => { createButton()?.click(); });
expect(onCommit).toHaveBeenCalledWith("", {
- startDate: "2026-06-05", endDate: null, startTime: "14:00", endTime: "15:30"
+ startDate: "2026-06-05", startTime: "14:00", endTime: "15:30"
});
});
@@ -168,6 +168,6 @@ describe("GhostPopover", () => {
expect(timeInputs()).toHaveLength(0);
expect(document.activeElement).toBe(document.querySelector(".calendar-event-add-time"));
await act(async () => { createButton()?.click(); });
- expect(onCommit).toHaveBeenCalledWith("", { startDate: "2026-06-05", startTime: null, endTime: null, endDate: null });
+ expect(onCommit).toHaveBeenCalledWith("", { startDate: "2026-06-05", startTime: null, endTime: null });
});
});
diff --git a/apps/client/src/widgets/collections/calendar/selection.spec.ts b/apps/client/src/widgets/collections/calendar/selection.spec.ts
index 674d69a952..2c4b19e58a 100644
--- a/apps/client/src/widgets/collections/calendar/selection.spec.ts
+++ b/apps/client/src/widgets/collections/calendar/selection.spec.ts
@@ -47,13 +47,13 @@ describe("withAllDay", () => {
.toEqual({ startDate: "2026-06-05", endDate: "2026-06-06", startTime: null, endTime: null });
});
- it("gives a whole-day draft default hours within its first day", () => {
+ it("gives a whole-day draft default hours and keeps its days", () => {
expect(withAllDay({ startDate: "2026-06-05", endDate: "2026-06-07" }, false))
- .toEqual({ startDate: "2026-06-05", endDate: null, startTime: "09:00", endTime: "10:00" });
+ .toEqual({ startDate: "2026-06-05", endDate: "2026-06-07", startTime: "09:00", endTime: "10:00" });
});
it("keeps an end time the event already holds when hours are added", () => {
expect(withAllDay({ startDate: "2026-06-05", endTime: "11:30" }, false))
- .toEqual({ startDate: "2026-06-05", endDate: null, startTime: "09:00", endTime: "11:30" });
+ .toEqual({ startDate: "2026-06-05", startTime: "09:00", endTime: "11:30" });
});
});
diff --git a/apps/client/src/widgets/collections/calendar/selection.ts b/apps/client/src/widgets/collections/calendar/selection.ts
index 7dd80af6c6..0d500cf600 100644
--- a/apps/client/src/widgets/collections/calendar/selection.ts
+++ b/apps/client/src/widgets/collections/calendar/selection.ts
@@ -16,15 +16,15 @@ const DEFAULT_END_TIME = "10:00";
/**
* Switches an event between all-day and timed, for the new-event popup and the event popover
- * alike (see EventDatesFields). A timed event spans a single day, so adding hours drops the end
- * date. An end time the event already holds is kept.
+ * alike (see EventDatesFields). The days are kept either way, a timed event being able to span
+ * several of them, and so is an end time the event already holds.
*/
export function withAllDay(draft: EventDraft, allDay: boolean): EventDraft {
if (allDay) {
return { ...draft, startTime: null, endTime: null };
}
- return { ...draft, endDate: null, startTime: DEFAULT_START_TIME, endTime: draft.endTime ?? DEFAULT_END_TIME };
+ return { ...draft, startTime: DEFAULT_START_TIME, endTime: draft.endTime ?? DEFAULT_END_TIME };
}
/** A point in viewport coordinates — where a click or a drag's end fell, anchoring a popover
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html
index fc68e415a4..51d3eb6449 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html
@@ -42,8 +42,10 @@
a day in the month view), press <em>Add time</em> and set the start and end
time; the duration is shown to the right of them. To make the event all-day
again, press the <span class="tn-icon bx bx-x"></span> button at the end
- of the row. A timed event spans a single day, so adding a time to a range
- of days keeps only the first one.</p>
+ of the row. Adding or removing a time keeps the dates, so an event can
+ start at a time on one day and end at a time on another (for example, a
+ night shift). If the end date is left empty, the event ends on the day
+ it starts, or on the next day when the end time is before the start time.</p>
<p>After creating the event, it will show up on the calendar. To edit the
content of the event (including recurrence), click on it to bring it into
the popup view.</p>
@@ -85,7 +87,7 @@
</li>
<li>Calendar-specific features:
<ul>
- <li>The date, or the first and last day for an all-day event.</li>
+ <li>The start date and, for an event spanning several days, the end date.</li>
<li>The start and end time with the duration to the right of them, and a <span
class="tn-icon bx bx-x"></span> button that removes the time, making the
event all-day. An all-day event shows an <em>Add time</em> button instead.</li>
diff --git a/docs/User Guide/User Guide/Collections/Calendar.md b/docs/User Guide/User Guide/Collections/Calendar.md
index 0aa41dab9c..11434b33a9 100644
--- a/docs/User Guide/User Guide/Collections/Calendar.md
+++ b/docs/User Guide/User Guide/Collections/Calendar.md
@@ -28,7 +28,7 @@ In either cases, a small popup will show with a prompt for a title and the date
At this point, the event hasn't been created yet to protect against accidental clicks. Add a title optionally and press the _Create_ button. If no title is provided, the event will follow the <a class="reference-link" href="../Advanced%20Usage/Default%20Note%20Title.md">Default Note Title</a> rules.
-To give the event a time before creating it (for example, after clicking a day in the month view), press _Add time_ and set the start and end time; the duration is shown to the right of them. To make the event all-day again, press the <span class="tn-icon bx bx-x"></span> button at the end of the row. A timed event spans a single day, so adding a time to a range of days keeps only the first one.
+To give the event a time before creating it (for example, after clicking a day in the month view), press _Add time_ and set the start and end time; the duration is shown to the right of them. To make the event all-day again, press the <span class="tn-icon bx bx-x"></span> button at the end of the row. Adding or removing a time keeps the dates, so an event can start at a time on one day and end at a time on another (for example, a night shift). If the end date is left empty, the event ends on the day it starts, or on the next day when the end time is before the start time.
After creating the event, it will show up on the calendar. To edit the content of the event (including recurrence), click on it to bring it into the popup view.
@@ -56,7 +56,7 @@ When an event is clicked, a popup will show near the event which contains the fo
* Color picker to change the color of the event.
* Button to remove the event from the calendar, which can optionally delete its corresponding note.
* Calendar-specific features:
- * The date, or the first and last day for an all-day event.
+ * The start date and, for an event spanning several days, the end date.
* The start and end time with the duration to the right of them, and a <span class="tn-icon bx bx-x"></span> button that removes the time, making the event all-day. An all-day event shows an _Add time_ button instead.
* A full recurrence editor, opened from the dropdown below the time, to have the same event show up weekly, monthly, etc.
* The <a class="reference-link" href="../Advanced%20Usage/Attributes/Promoted%20Attributes.md">Promoted Attributes</a> of the marker, if any.