src/utils.js
function fillBackWeek({
  lastDayOfMonth,
  minDate,
  maxDate,
  selectedDates,
  firstDayOfWeek,
  showOutsideDays
}) {
  const dates = [];
  let lastDay = (lastDayOfMonth.getDay() + 7 - firstDayOfWeek) % 7;

  if (showOutsideDays) {
    const firstDayOfNextMonth = addDays(lastDayOfMonth, 1);
    const nextDateMonth = firstDayOfNextMonth.getMonth();
    const nextDateYear = firstDayOfNextMonth.getFullYear();

    // Fill out back week for days from
    // following month with dates from next month.
    let counter = 0;
    while (counter < 6 - lastDay) {
      const date = new Date(nextDateYear, nextDateMonth, 1 + counter);
      const dateObj = {
        date,
        selected: isSelected(selectedDates, date),
        selectable: isSelectable(minDate, maxDate, date),
        today: false,
        prevMonth: false,
        nextMonth: true
      };
      dates.push(dateObj);
      counter++;
    }
  } else {
    // Fill out back week for days from
    // following month with buffer.
    while (lastDay < 6) {
      dates.push('');
      lastDay++;
    }
  }

  return dates;
}
function fillBackWeek({
  lastDayOfMonth,
  minDate,
  maxDate,
  selectedDates,
  firstDayOfWeek,
  showOutsideDays
}) {
  const dates = [];
  let lastDay = (lastDayOfMonth.getDay() + 7 - firstDayOfWeek) % 7;

  if (showOutsideDays) {
    const firstDayOfNextMonth = addDays(lastDayOfMonth, 1);
    const nextDateMonth = firstDayOfNextMonth.getMonth();
    const nextDateYear = firstDayOfNextMonth.getFullYear();

    // Fill out back week for days from
    // following month with dates from next month.
    let counter = 0;
    while (counter < 6 - lastDay) {
      const date = new Date(nextDateYear, nextDateMonth, 1 + counter);
      const dateObj = {
        date,
        selected: isSelected(selectedDates, date),
        selectable: isSelectable(minDate, maxDate, date),
        today: false,
        prevMonth: false,
        nextMonth: true
      };
      dates.push(dateObj);
      counter++;
    }
  } else {
    // Fill out back week for days from
    // following month with buffer.
    while (lastDay < 6) {
      dates.push('');
      lastDay++;
    }
  }

  return dates;
}
function fillBackWeek ( { lastDayOfMonth , minDate , maxDate , selectedDates , firstDayOfWeek , showOutsideDays } ) { const dates = [ ] ; let lastDay = ( lastDayOfMonth . getDay ( ) + 7 - firstDayOfWeek ) % 7 ; if ( showOutsideDays ) { const firstDayOfNextMonth = addDays ( lastDayOfMonth , 1 ) ; const nextDateMonth = firstDayOfNextMonth . getMonth ( ) ; const nextDateYear = firstDayOfNextMonth . getFullYear ( ) ; // Fill out back week for days from // following month with dates from next month. let counter = 0 ; while ( counter < 6 - lastDay ) { const date = new Date ( nextDateYear , nextDateMonth , 1 + counter ) ; const dateObj = { date , selected : isSelected ( selectedDates , date ) , selectable : isSelectable ( minDate , maxDate , date ) , today : false , prevMonth : false , nextMonth : true } ; dates . push ( dateObj ) ; counter ++ ; } } else { // Fill out back week for days from // following month with buffer. while ( lastDay < 6 ) { dates . push ( '' ) ; lastDay ++ ; } } return dates ; }
Fill back weeks with either empty buffer or dates from next month,
depending on showOutsideDays flag
@param {Object} param The param object
@param {Array.<Date>} param.selectedDates An array of dates currently selected
@param {Date} param.minDate The earliest date available
@param {Date} param.maxDate The furthest date available
@param {Date} param.lastDayOfMonth Last day of the month
@param {Number} param.firstDayOfWeek First day of week, 0-6 (Sunday to Saturday)
@param {Bool} param.showOutsideDays Flag to fill front and back weeks with dates from adjacent months
@returns {Array.<Date>} Buffer to fill back week
Fill back weeks with either empty buffer or dates from next month depending on showOutsideDays flag