Holidays here in UK shift, not sure of US. I think I would create an array of holiday iso timestamps, the loop through to create count of holidays that are weekdays and between the startDate and finishDate.
e.g.
[{"id":"9aacb749e03a522c","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"fromDate","v":"2022-05-02T00:00:00.000Z","vt":"str"},{"p":"toDate","v":"2022-11-11T23:59:00.000Z","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":3420,"wires":[["403db4b1082bddf0"]]},{"id":"403db4b1082bddf0","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"\"https://api.generadordni.es/v2/holidays/holidays?country=US&year=\" & $moment().format(\"YYYY\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":3420,"wires":[["56d0f4ca24930802"]]},{"id":"56d0f4ca24930802","type":"http request","z":"452103ea51141731","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":470,"y":3420,"wires":[["a743bdc005103478","308ef04085e71f3b"]]},{"id":"a743bdc005103478","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[$$.payload.start]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":3420,"wires":[["88773e494c57f6ac","308ef04085e71f3b"]]},{"id":"308ef04085e71f3b","type":"debug","z":"452103ea51141731","name":"debug 108","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":3380,"wires":[]},{"id":"88773e494c57f6ac","type":"function","z":"452103ea51141731","name":"function 17","func":"let startDate = new Date(msg.fromDate);\nlet finishDate = new Date(msg.toDate);\nlet count_hols = msg.payload.reduce((acc, str) => {\n let date = new Date(str);\n let day = date.getDay();\n if(day > 0 && day < 6 && date >= startDate && date <= finishDate){\n acc++;\n }\n return acc;\n},0)\n\nlet weekDayCount = 0;\nwhile (startDate < finishDate) {\n if (startDate.getDay() > 0 && startDate.getDay() < 6) {\n weekDayCount++; \n }\n startDate.setDate(startDate.getDate() + 1);\n}\nmsg.payload = weekDayCount - count_hols;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":3480,"wires":[["1ed7b575b8922ee8"]]},{"id":"1ed7b575b8922ee8","type":"debug","z":"452103ea51141731","name":"debug 107","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":3600,"wires":[]}]
You could also add 2023 to the array to allow for cross year periods.
//create start and finish time objectst starte objects
let startDate = new Date(msg.fromDate);
let finishDate = new Date(msg.toDate);
//loop through holiday iso strings to check if between date and a weekday
let count_hols = msg.payload.reduce((acc, str) => {
let date = new Date(str);
let day = date.getDay();
if(day > 0 && day < 6 && date >= startDate && date <= finishDate){
acc++;
}
return acc;
},0)
// lopp through start and finish time period and check for weekday
let weekDayCount = 0;
while (startDate < finishDate) {
if (startDate.getDay() > 0 && startDate.getDay() < 6) {
weekDayCount++;
}
startDate.setDate(startDate.getDate() + 1);
}
//subtract hols from weekdays
msg.payload = weekDayCount - count_hols;
return msg;
The api call for holidays could be run once a year on Jan 1st to update a context var of iso holiday timestamps.