This code finds split weeks for a given year.
To use the code, define year as the year to find split weeks for. Then call the getMonthlyDates and isSplitWeek functions.
let year = new Date().getFullYear()
console.log(`Finding Split weeks for year ${year}`)
let lastDates = getMonthlyDates(new Date(year, 0, 31), 12);
lastDates.forEach(d => {
console.log(`is split week:`, isSplitWeek(d));
});The getMonthlyDates function takes a start date and a count and returns the last day of each month for the specified range, starting from the start date.
The isSplitWeek function takes a date and returns true or false, depending on if it is a split week or not.
Using the code above, the output for 2020 would look like this:
Finding Split weeks for year 2020
Tue Dec 31 2019 00:00:00 GMT-0800 (Pacific Standard Time)
Week ends on Tuesday:
is split week: true
Wed Jan 29 2020 00:00:00 GMT-0800 (Pacific Standard Time)