js/master.js
/* Days between two dates function that works with daylight saving time.
 * Sources:
 * https://stackoverflow.com/a/2627482 (2019-10-06).
 * https://stackoverflow.com/a/4943116 (2019-10-06).
 */
Days between two dates function that works with daylight saving time.
Days between two dates function that works with daylight saving time .
function daysBetween (startDate, endDate) {
  if (
    startDate.isDstObserved() && !endDate.isDstObserved()
  ) {
    startDate.setHours(startDate.getHours() + 1);
  } else if (
    !startDate.isDstObserved() && endDate.isDstObserved()
  ) {
    startDate.setHours(startDate.getHours() - 1);
  }
  const ONE_DAY = 1000 * 60 * 60 * 24;
  const differenceMs = Math.abs(startDate - endDate);
  return Math.floor(differenceMs / ONE_DAY) + 1;
}
function daysBetween ( startDate , endDate ) { if ( startDate . isDstObserved ( ) && ! endDate . isDstObserved ( ) ) { startDate . setHours ( startDate . getHours ( ) + 1 ) ; } else if ( ! startDate . isDstObserved ( ) && endDate . isDstObserved ( ) ) { startDate . setHours ( startDate . getHours ( ) - 1 ) ; } const ONE_DAY = 1000 * 60 * 60 * 24 ; const differenceMs = Math . abs ( startDate - endDate ) ; return Math . floor ( differenceMs / ONE_DAY ) + 1 ; }
Days between two dates function that works with daylight saving time.
Days between two dates function that works with daylight saving time .
/* Logic that will fix DST problems:
   1. If both dates are either DST or not, do nothing.
   2. If only start date is DST, add one hour to start date.
   3. If only end date is DST, subtract one hour to start date.
   */ // The number of milliseconds in one day // Calculate the difference in milliseconds // Convert back to days and return