JSFiddle - React, Tailwind, and code Playground
by Sergey Denisov
HTML
<div class="demo"></div>
JavaScript
function printInterval(startDate, maxInvoice) {
var splitSrt = startDate.split('-');
var dateSrt = new Date(splitSrt[2], splitSrt[1] - 1, splitSrt[0]);
var currentDay = dateSrt.getDate();
var billsCount = 6;
$('.demo').append('<div><b>Start date: ' + startDate + ', Max Invoice: ' + maxInvoice + '</b></div>');
for (var i = 0, j = 0; i < billsCount; i++) {
var newDate = new Date(dateSrt.getTime());
newDate.setMonth(dateSrt.getMonth() + j, currentDay);
if (newDate.getMonth() > (dateSrt.getMonth() + j) % 12) {
newDate.setDate(0);
}
var txtDay = $.datepicker.formatDate('dd-mm-yy', newDate);
$('.demo').append('<div>'+ (i + 1) + '. Invoice ' + (i + 1) + ': ' + txtDay + '</div>');
if (i === 0) {
j += 5;
} else if (i === 1) {
j += 7;
} else {
j += maxInvoice;
}
}
}
printInterval('30-09-2015', 6);
printInterval('31-08-2018', 6);