JSFiddle - React, Tailwind, and code Playground

by saitam

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-business-days/1.2.0/index.js"></script>

JavaScript

myHolidays = [
  { holidayDate: "2020-06-01", description: "holiday 1" },
  { holidayDate: "2020-06-02", description: "holiday 2" },
  { holidayDate: "2020-06-03", description: "holiday 3" },  
  { holidayDate: "2020-06-06", description: "weekend saturday" },
  { holidayDate: "2020-06-07", description: "weekend sunday" },
  { holidayDate: "2020-06-11", description: "holiday 6" },
  { holidayDate: "2020-06-13", description: "weekend saturday" },
  { holidayDate: "2020-06-14", description: "weekend sunday" },
  { holidayDate: "2020-06-20", description: "weekend saturday" },
  { holidayDate: "2020-06-21", description: "weekend sunday" },
  { holidayDate: "2020-06-27", description: "weekend saturday" },
  { holidayDate: "2020-06-28", description: "weekend sunday" },
];

moment.updateLocale('de', {
   holidays: myHolidays.map(i => i.holidayDate),
   holidayFormat: 'YYYY-MM-DD'
});

var startDate = moment("2020-01-01").startOf('month')
var endDate = moment("2020-12-01")
var eachMonthWith16 = [];

function generate16InEachMonth() {
  let monthsList = []
  // loop by months
  while (endDate > startDate) {
    monthsList.push(new Date(moment(this.startDate).businessAdd(15, 'days')))
    startDate = startDate.add(1, "month").startOf('month')
  }
  return monthsList
}

console.log(generate16InEachMonth())