///// !!! home.php !!! ///// // Target the input fields to be updated let startDate = document.querySelector('input[name=start]'); let endDate = document.querySelector('input[name=end]'); let duration = document.querySelector('input[name=duration]'); // For new experiences, the minimum start date is tomorrow and the maximum is a year from tomorrow function setStartDateRange() { /* Compute the today, tomorrow and the year after tomorrow */ // let today = new Date(); // today.setHours(0, 0, 0, 0); // (default to 00:00:00) // let tomorrow = new Date(today); // tomorrow.setDate(tomorrow.getDate() + 1); // let aYearFromTomorrow = new Date(tomorrow); // aYearFromTomorrow.setDate(aYearFromTomorrow.getDate() + 365); // Set minimum start date to tomorrow // startDate.min = tomorrow.toLocaleDateString(); // Set maximum start date to a year from tomorrow // startDate.max = aYearFromTomorrow.toLocaleDateString(); if(!isNaN(Date.parse(startDate.value)) && !isNaN(Date.parse(endDate.value))) { if(Date.parse(startDate.value) > Date.parse(endDate.value)) { endDate.value = startDate.value; } } } // For new experiences, the minimum end date is the day after the start date and the maximum is a year from the minimum end date function setEndDateRange() { /* Compute the day after the start date value, and the year after that */ // let dayAfterStart = new Date(startDate.value); // dayAfterStart.setDate(dayAfterStart.getDate() + 1 + 1); // (additional 1 necessary because of line above, apparent 0-indexing) // let aYearFromMinimumEnd = new Date(dayAfterStart); // aYearFromMinimumEnd.setDate(aYearFromMinimumEnd.getDate() + 365); // Set minimum end date to the day after the start date // endDate.min = dayAfterStart.toLocaleDateString(); // Set maximum end date to a year from the minimum end date // endDate.max = aYearFromMinimumEnd.toLocaleDateString(); if(!isNaN(Date.parse(startDate.value)) && !isNaN(Date.parse(endDate.value))) { if(Date.parse(startDate.value) > Date.parse(endDate.value)) { startDate.value = endDate.value; } } } // For new experiences, the duration (in weeks) will be the rounded weeks from start to end dates function setDuration() { // Calculate the duration in weeks x = new Date(startDate.value); x.setDate(x.getDate() + 1); // (additional 1 necessary because of line above, apparent 0-indexing) y = new Date(endDate.value); y.setDate(y.getDate() + 1); // (additional 1 necessary because of line above, apparent 0-indexing) duration.value = String(Math.max(Math.round((y - x) / 604800000), 0)); // (1000 * 60 * 60 * 24 * 7 = 604800000) }