fix: calendar event created late in the evening is saved ending a day late (#32199)

Creating a calendar event after 23:00 saved it ending on the day after the date picked, so it showed on two days. The new event form pre-fills an end time one hour from now, which falls on the next day, and that next-day end date was kept even when the event was set to other times. The end date now stays on the start date when the end time is later in the day than the start time. An event that ends after midnight or spans several days keeps its end date.

Fixes #31994
This commit is contained in:
Classic298 2026-10-10 18:15:25 +02:00 • committed by GitHub
parent c2a5c7a24e
commit 69a1c57328
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,6 +29,7 @@
let startTime = '';
let endDate = '';
let endDayOffset = 0;
let overnight = false;
let endTime = '';
let allDay = false;
let location = '';
@ -76,6 +77,10 @@
return new Date(`${dateStr}T${timeStr || '00:00'}`).getTime() * NS;
}
function endsPastMidnight(): boolean {
return !allDay && endTime < startTime;
}
function reset() {
if (event) {
title = event.title;
@ -118,6 +123,7 @@
(24 * 60 * 60 * 1000 * NS)
)
: 0;
overnight = endDayOffset === 1 && endsPastMidnight();
}
$: if (show) reset();
@ -136,8 +142,9 @@
loading = true;
try {
const startNs = dateTimeToNs(startDate, allDay ? '00:00' : startTime);
const endDays = overnight && !endsPastMidnight() ? 0 : endDayOffset;
const shiftedEndDate = endDate
? nsToDateStr(dateTimeToNs(startDate, '12:00') + endDayOffset * 24 * 60 * 60 * 1000 * NS)
? nsToDateStr(dateTimeToNs(startDate, '12:00') + endDays * 24 * 60 * 60 * 1000 * NS)
: '';
let endNs = shiftedEndDate
? dateTimeToNs(shiftedEndDate, allDay ? '23:59' : endTime)