Sin descripción

home.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ///// !!! home.php !!! /////
  2. // Target the input fields to be updated
  3. let startDate = document.querySelector('input[name=start]');
  4. let endDate = document.querySelector('input[name=end]');
  5. // let duration = document.querySelector('input[name=duration]');
  6. // For new experiences, the minimum start date is tomorrow and the maximum is a year from tomorrow
  7. function setStartDateRange() {
  8. /* Compute the today, tomorrow and the year after tomorrow */
  9. // let today = new Date();
  10. // today.setHours(0, 0, 0, 0); // (default to 00:00:00)
  11. // let tomorrow = new Date(today);
  12. // tomorrow.setDate(tomorrow.getDate() + 1);
  13. // let aYearFromTomorrow = new Date(tomorrow);
  14. // aYearFromTomorrow.setDate(aYearFromTomorrow.getDate() + 365);
  15. // Set minimum start date to tomorrow
  16. // startDate.min = tomorrow.toLocaleDateString();
  17. // Set maximum start date to a year from tomorrow
  18. // startDate.max = aYearFromTomorrow.toLocaleDateString();
  19. if(!isNaN(Date.parse(startDate.value)) && !isNaN(Date.parse(endDate.value))) {
  20. if(Date.parse(startDate.value) > Date.parse(endDate.value)) {
  21. endDate.value = startDate.value;
  22. }
  23. }
  24. }
  25. // 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
  26. function setEndDateRange() {
  27. /* Compute the day after the start date value, and the year after that */
  28. // let dayAfterStart = new Date(startDate.value);
  29. // dayAfterStart.setDate(dayAfterStart.getDate() + 1 + 1); // (additional 1 necessary because of line above, apparent 0-indexing)
  30. // let aYearFromMinimumEnd = new Date(dayAfterStart);
  31. // aYearFromMinimumEnd.setDate(aYearFromMinimumEnd.getDate() + 365);
  32. // Set minimum end date to the day after the start date
  33. // endDate.min = dayAfterStart.toLocaleDateString();
  34. // Set maximum end date to a year from the minimum end date
  35. // endDate.max = aYearFromMinimumEnd.toLocaleDateString();
  36. if(!isNaN(Date.parse(startDate.value)) && !isNaN(Date.parse(endDate.value))) {
  37. if(Date.parse(startDate.value) > Date.parse(endDate.value)) {
  38. startDate.value = endDate.value;
  39. }
  40. }
  41. }
  42. // For new experiences, the duration (in weeks) will be the rounded weeks from start to end dates
  43. function setDuration() {
  44. // Calculate the duration in weeks
  45. x = new Date(startDate.value);
  46. x.setDate(x.getDate() + 1); // (additional 1 necessary because of line above, apparent 0-indexing)
  47. y = new Date(endDate.value);
  48. y.setDate(y.getDate() + 1); // (additional 1 necessary because of line above, apparent 0-indexing)
  49. // duration.value = String(Math.max(Math.round((y - x) / 604800000), 0)); // (1000 * 60 * 60 * 24 * 7 = 604800000)
  50. }