Preserve time difference when changing start date (fixes #596)

This commit is contained in:
Mike Sheldon
2025-03-20 21:24:52 +00:00
committed by setop
parent fce01fd387
commit bfe00e5bd7

View File

@@ -1312,7 +1312,7 @@ watch(endsOn, (newEndsOn) => {
updateEventDateRelatedToTimezone();
});
/*
/*
For endsOn, we need to check consistencyBeginsOnBeforeEndsOn() at blur
because the datetime-local component update itself immediately
Ex : your event start at 10:00 and stops at 12:00
@@ -1322,9 +1322,18 @@ So you cannot check consistensy in real time, only onBlur because of the moment
const consistencyBeginsOnBeforeEndsOn = () => {
// Update endsOn to make sure endsOn is later than beginsOn
if (endsOn.value && beginsOn.value && endsOn.value <= beginsOn.value) {
const newEndsOn = new Date(beginsOn.value);
newEndsOn.setUTCHours(beginsOn.value.getUTCHours() + 1);
// If the start date has changed, preserve the time difference
const newEndsOn = new Date(endsOn.value);
newEndsOn.setDate(beginsOn.value.getDate());
newEndsOn.setMonth(beginsOn.value.getMonth());
newEndsOn.setFullYear(beginsOn.value.getFullYear());
endsOn.value = newEndsOn;
// If the end time is still earlier than the start time set a 1 hour difference
if (endsOn.value <= beginsOn.value) {
const newEndsOn2 = new Date(beginsOn.value);
newEndsOn2.setUTCHours(beginsOn.value.getUTCHours() + 1);
endsOn.value = newEndsOn2;
}
}
};