src/CalendarHeader.js
//It also formats the month section if the week is in between months
It also formats the month section if the week is in between months
It also formats the month section if the week is in between months
formatCalendarHeader(startingDate, calendarHeaderFormat) {
    let firstDay = startingDate;
    let lastDay = startingDate.clone().add(6, "days");
    let monthFormatting = "";
    if ((calendarHeaderFormat.match(/Mo/g) || []).length > 0) {
      monthFormatting = "Mo";
    } else {
      if ((calendarHeaderFormat.match(/M/g) || []).length > 0) {
        for (
          let i = (calendarHeaderFormat.match(/M/g) || []).length;
          i > 0;
          i--
        ) {
          monthFormatting += "M";
        }
      }
    }
    if (firstDay.month() === lastDay.month()) {
      return firstDay.format(calendarHeaderFormat);
    } else if (firstDay.year() !== lastDay.year()) {
      return `${firstDay.format(calendarHeaderFormat)} / ${lastDay.format(calendarHeaderFormat)}`;
    }
    return `${monthFormatting.length > 1 ? firstDay.format(monthFormatting) : ""} ${monthFormatting.length > 1 ? "/" : ""} ${lastDay.format(calendarHeaderFormat)}`;
  }
formatCalendarHeader ( startingDate , calendarHeaderFormat ) { let firstDay = startingDate ; let lastDay = startingDate . clone ( ) . add ( 6 , "days" ) ; let monthFormatting = "" ; if ( ( calendarHeaderFormat . match ( / Mo / g ) || [ ] ) . length > 0 ) { monthFormatting = "Mo" ; } else { if ( ( calendarHeaderFormat . match ( / M / g ) || [ ] ) . length > 0 ) { for ( let i = ( calendarHeaderFormat . match ( / M / g ) || [ ] ) . length ; i > 0 ; i -- ) { monthFormatting += "M" ; } } } if ( firstDay . month ( ) === lastDay . month ( ) ) { return firstDay . format ( calendarHeaderFormat ) ; } else if ( firstDay . year ( ) !== lastDay . year ( ) ) { return ` ${ firstDay . format ( calendarHeaderFormat ) } ${ lastDay . format ( calendarHeaderFormat ) } ` ; } return ` ${ monthFormatting . length > 1 ? firstDay . format ( monthFormatting ) : "" } ${ monthFormatting . length > 1 ? "/" : "" } ${ lastDay . format ( calendarHeaderFormat ) } ` ; }
It also formats the month section if the week is in between months
It also formats the month section if the week is in between months
//Parsing the month part of the user defined formating