This an example using 07-01-2021 for a start-date, and being prejudice against the weekends...
- Code: Select all
start = new Date(2021,06,00);
function nextWorkDay(start, counter) {
while (counter > 0) { start.setDate(start.getDate() + 1);
if (start.getDay() != 0 && start.getDay() != 6) { counter -= 1 }
}
return start }
newName = nextWorkDay(start, counter) + '___' + name
But this output is very terrible looking, because the dates get invented looking like this...
Thu Jul 01 2021 00:00:00 GMT-0700 (Pacific Daylight Time)___File1.txt
Fri Jul 02 2021 00:00:00 GMT-0700 (Pacific Daylight Time)___File2.txt
Mon Jul 05 2021 00:00:00 GMT-0700 (Pacific Daylight Time)___File3.txt
Tue Jul 06 2021 00:00:00 GMT-0700 (Pacific Daylight Time)___File4.txt
So for me, Im just downloaded the "moment.js" because then its much easier to format the dates with...
- Code: Select all
require('js/moment.js')
start = new Date(2021,06,00)
function nextWorkDay(start, counter) {
while (counter > 0) { start.setDate(start.getDate() + 1);
if (start.getDay() != 0 && start.getDay() != 6) { counter -= 1 }
}
return start }
newName = moment(nextWorkDay(start, counter)).format('YYYY-MM-DD') + '___' + name
So then its not so bad, because now looking more like...
2021-07-01___File1.txt
2021-07-02___File2.txt
2021-07-05___File3.txt
2021-07-06___File4.txt
Except still this code will
not use 08-01-2021 as the last-date in your range, so if you can modify, please do post the solution.
Im just copied the function from stackexchange, and then modified the variables, but not really understanding how it conducts.