Use Date.getTime instead of relaying on implicit conversion

Otherwise, fucking IntelliJ does not shut up about imaginary problems.
This commit is contained in:
jordi fita mas 2024-02-02 02:51:38 +01:00
parent 28adeb38fc
commit 33a1f0f4e2
1 changed files with 4 additions and 3 deletions

View File

@ -3,7 +3,7 @@
function updateDepartureDate(arrivalDateField) {
const arrivalDate = new Date(arrivalDateField.value);
if (isNaN(arrivalDate)) {
if (isNaN(arrivalDate.getTime())) {
return;
}
const departureDateField = document.querySelector('[name="departure_date"]');
@ -17,7 +17,8 @@
departureDateField.setAttribute('min', minDate);
const departureDate = new Date(departureDateField.value);
if (isNaN(departureDate) || departureDate < arrivalDate) {
const validDepartureDate = !isNaN(departureDate.getTime())
if (!validDepartureDate || departureDate < arrivalDate) {
departureDateField.value = minDate;
}
@ -26,7 +27,7 @@
arrivalDate.setUTCDate(arrivalDate.getUTCDate() + maxNights - minNights);
const maxDate = formatDate(arrivalDate);
departureDateField.setAttribute('max', maxDate);
if (!isNaN(departureDate) && departureDate >= arrivalDate) {
if (validDepartureDate && departureDate >= arrivalDate) {
departureDateField.value = maxDate;
}
}