Preserve time difference when changing start date (fixes #596)
This commit is contained in:
@@ -1312,7 +1312,7 @@ watch(endsOn, (newEndsOn) => {
|
|||||||
updateEventDateRelatedToTimezone();
|
updateEventDateRelatedToTimezone();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
For endsOn, we need to check consistencyBeginsOnBeforeEndsOn() at blur
|
For endsOn, we need to check consistencyBeginsOnBeforeEndsOn() at blur
|
||||||
because the datetime-local component update itself immediately
|
because the datetime-local component update itself immediately
|
||||||
Ex : your event start at 10:00 and stops at 12:00
|
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 = () => {
|
const consistencyBeginsOnBeforeEndsOn = () => {
|
||||||
// Update endsOn to make sure endsOn is later than beginsOn
|
// Update endsOn to make sure endsOn is later than beginsOn
|
||||||
if (endsOn.value && beginsOn.value && endsOn.value <= beginsOn.value) {
|
if (endsOn.value && beginsOn.value && endsOn.value <= beginsOn.value) {
|
||||||
const newEndsOn = new Date(beginsOn.value);
|
// If the start date has changed, preserve the time difference
|
||||||
newEndsOn.setUTCHours(beginsOn.value.getUTCHours() + 1);
|
const newEndsOn = new Date(endsOn.value);
|
||||||
|
newEndsOn.setDate(beginsOn.value.getDate());
|
||||||
|
newEndsOn.setMonth(beginsOn.value.getMonth());
|
||||||
|
newEndsOn.setFullYear(beginsOn.value.getFullYear());
|
||||||
endsOn.value = newEndsOn;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user