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

  if (showOutsideDays) {
    const lastDayOfPrevMonth = addDays(firstDayOfMonth, -1);
    const prevDate = lastDayOfPrevMonth.getDate();
    const prevDateMonth = lastDayOfPrevMonth.getMonth();
    const prevDateYear = lastDayOfPrevMonth.getFullYear();

    // Fill out front week for days from
    // preceding month with dates from previous month.
    let counter = 0;
    while (counter < firstDay) {
      const date = new Date(prevDateYear, prevDateMonth, prevDate - counter);
      const dateObj = {
        date,
        selected: isSelected(selectedDates, date),
        selectable: isSelectable(minDate, maxDate, date),
        today: false,
        prevMonth: true,
        nextMonth: false
      };
      dates.unshift(dateObj);
      counter++;
    }
  } else {
    // Fill out front week for days from
    // preceding month with buffer.
    while (firstDay > 0) {
      dates.unshift('');
      firstDay--;
    }
  }

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

  if (showOutsideDays) {
    const lastDayOfPrevMonth = addDays(firstDayOfMonth, -1);
    const prevDate = lastDayOfPrevMonth.getDate();
    const prevDateMonth = lastDayOfPrevMonth.getMonth();
    const prevDateYear = lastDayOfPrevMonth.getFullYear();

    // Fill out front week for days from
    // preceding month with dates from previous month.
    let counter = 0;
    while (counter < firstDay) {
      const date = new Date(prevDateYear, prevDateMonth, prevDate - counter);
      const dateObj = {
        date,
        selected: isSelected(selectedDates, date),
        selectable: isSelectable(minDate, maxDate, date),
        today: false,
        prevMonth: true,
        nextMonth: false
      };
      dates.unshift(dateObj);
      counter++;
    }
  } else {
    // Fill out front week for days from
    // preceding month with buffer.
    while (firstDay > 0) {
      dates.unshift('');
      firstDay--;
    }
  }

  return dates;
}
function fillFrontWeek ( { firstDayOfMonth , minDate , maxDate , selectedDates , firstDayOfWeek , showOutsideDays } ) { const dates = [ ] ; let firstDay = ( firstDayOfMonth . getDay ( ) + 7 - firstDayOfWeek ) % 7 ; if ( showOutsideDays ) { const lastDayOfPrevMonth = addDays ( firstDayOfMonth , - 1 ) ; const prevDate = lastDayOfPrevMonth . getDate ( ) ; const prevDateMonth = lastDayOfPrevMonth . getMonth ( ) ; const prevDateYear = lastDayOfPrevMonth . getFullYear ( ) ; // Fill out front week for days from // preceding month with dates from previous month. let counter = 0 ; while ( counter < firstDay ) { const date = new Date ( prevDateYear , prevDateMonth , prevDate - counter ) ; const dateObj = { date , selected : isSelected ( selectedDates , date ) , selectable : isSelectable ( minDate , maxDate , date ) , today : false , prevMonth : true , nextMonth : false } ; dates . unshift ( dateObj ) ; counter ++ ; } } else { // Fill out front week for days from // preceding month with buffer. while ( firstDay > 0 ) { dates . unshift ( '' ) ; firstDay -- ; } } return dates ; }
Fill front week with either empty buffer or dates from previous 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.firstDayOfMonth First 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 front week
Fill front week with either empty buffer or dates from previous month depending on showOutsideDays flag