node-red-contrib-cron-plus icon indicating copy to clipboard operation
node-red-contrib-cron-plus copied to clipboard

Feature request: Possibility to add holidays in countries

Open provaid82 opened this issue 1 year ago • 1 comments

Possibility to add holidays in countries , something like date-holidays and possibility if is holiday to run or not run , delay and stuff like this

provaid82 avatar Dec 25 '23 12:12 provaid82

Hi, that is a big ask.

While I think it would be a nice feature, there are many considerations to make. Off the top of my head: would this be "per schedule" or "per node". Would it simply "not trigger" or "trigger with a flag"? How would updates be installed (i think it would require user to do an NPM update to get latest dates)

TBH, I think a separate node would be a better fit. Because users not using cron-plus (or for other situations not invliving cron/timed events) would be able to make use of it. This is the "better" design pattern where nodes are atomic (i.e. a good node typically does one thing and does it well!)

And note: you can do this yourself without waiting for someone to develop a specific node by simply importing date-holidays into a function node and testing the date yourself and permit the msg to continue or not.

Here is an example: chrome_AiqbeQTrkA

Demo flow

[{"id":"a5edd7b33a269eba","type":"function","z":"c2233fc1d8cc5c3b","name":"Is Holiday in 'US', 'la', 'no'?","func":"const hd = new Holidays('US', 'la', 'no')\nlet date = new Date()\nif (msg.dateCheck) {\n    date = new Date(msg.dateCheck)\n}\nmsg.checkDateDate = date\nconst holiday = hd.isHoliday(date)\n\nif (holiday) {\n    msg.holiday = holiday\n    return [null, msg] // output on port 2\n}\nreturn msg // output on port 1","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"Holidays","module":"date-holidays"}],"x":1310,"y":860,"wires":[["c61bb1828baf34b2"],["15df752ac1fe52b1"]]},{"id":"80579f2d7a2911b7","type":"inject","z":"c2233fc1d8cc5c3b","name":"a random cron event (today)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1020,"y":820,"wires":[["a5edd7b33a269eba"]]},{"id":"c61bb1828baf34b2","type":"debug","z":"c2233fc1d8cc5c3b","name":"No, not a holiday - lets process this message","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":1690,"y":840,"wires":[]},{"id":"15df752ac1fe52b1","type":"debug","z":"c2233fc1d8cc5c3b","name":"Yippe, its a holiday today, dont pass message on! ","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":1710,"y":900,"wires":[]},{"id":"722b8b587242c544","type":"inject","z":"c2233fc1d8cc5c3b","name":"Martin Luther King Jr. Day","props":[{"p":"payload"},{"p":"dateCheck","v":"2024-01-15 08:00","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1030,"y":880,"wires":[["a5edd7b33a269eba"]]}]

Steve-Mcl avatar Jan 08 '24 17:01 Steve-Mcl