From 9412cfc19faac2e266d644c528924e8b7f0b9303 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 16 Mar 2025 20:00:43 +0200 Subject: [PATCH] feat(calendar): support missing end time --- .../app/widgets/view_widgets/calendar_view.spec.ts | 13 +++++++++++++ .../app/widgets/view_widgets/calendar_view.ts | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/public/app/widgets/view_widgets/calendar_view.spec.ts b/src/public/app/widgets/view_widgets/calendar_view.spec.ts index 10ab38160..df6c8338c 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.spec.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.spec.ts @@ -160,4 +160,17 @@ describe("Promoted attributes", () => { expect(events[0]).toMatchObject({ title: "Note 1", start: "2025-05-05T13:36:00", end: "2025-05-05T14:56:00" }); expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07T13:36:00", end: "2025-05-08T14:56:00" }); }); + + it("handles start time with missing end time", async () => { + const noteIds = buildNotes([ + { title: "Note 1", "#startDate": "2025-05-05", "#startTime": "13:30" }, + { title: "Note 2", "#startDate": "2025-05-07", "#endDate": "2025-05-08", "#startTime": "13:36" }, + ]); + const events = await CalendarView.buildEvents(noteIds); + + expect(events).toHaveLength(2); + expect(events[0]).toMatchObject({ title: "Note 1", start: "2025-05-05T13:30:00", end: "2025-05-05T13:30:00" }); + expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07T13:36:00", end: "2025-05-08" }); + }); + }); diff --git a/src/public/app/widgets/view_widgets/calendar_view.ts b/src/public/app/widgets/view_widgets/calendar_view.ts index 700a74615..36e4a31ef 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.ts @@ -366,8 +366,9 @@ export default class CalendarView extends ViewMode { } for (const title of titles) { + startDate = (startTime ? `${startDate}T${startTime}:00` : startDate); if (!endDate) { - if (endTime) { + if (!endTime) { endDate = startDate; } else { const endDateOffset = CalendarView.#offsetDate(endDate ?? startDate, 1); @@ -377,7 +378,6 @@ export default class CalendarView extends ViewMode { } } - startDate = (startTime ? `${startDate}T${startTime}:00` : startDate); endDate = (endTime ? `${endDate}T${endTime}:00` : endDate); const eventData: EventInput = { title: title,