feat(calendar): support missing end time

This commit is contained in:
Elian Doran 2025-03-16 20:00:43 +02:00
parent 9083c18392
commit 9412cfc19f
No known key found for this signature in database
2 changed files with 15 additions and 2 deletions

View File

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

View File

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