How to calculate future time

@PinPat Are you using node-RED v1.3 or above?
If so, you could use the day.js package in a function node to both calculate the new time, and also format it to however you wish.
Day.js is a very lightweight package (2kB) and full docs are here.

Example Flow for node-RED v1.3 or above only - This will load the day.js package into node-RED's externalModules folder

dayjs

[{"id":"94c3a6b3.922108","type":"function","z":"b3b413d1.05b1b","name":"","func":"let now=dayjs().add(msg.payload, 'minutes');\nmsg.payload=(now.format(\"HH:mm:ss\"));\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"dayjs","module":"dayjs"}],"x":345,"y":1380,"wires":[["79269a6e.fa51e4"]]},{"id":"dadca7a6.ebc708","type":"inject","z":"b3b413d1.05b1b","name":"Add 30 mins","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","x":170,"y":1380,"wires":[["94c3a6b3.922108"]]},{"id":"79269a6e.fa51e4","type":"debug","z":"b3b413d1.05b1b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":1380,"wires":[]},{"id":"e84043ba.b05da","type":"inject","z":"b3b413d1.05b1b","name":"Add 45 mins","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"45","payloadType":"num","x":170,"y":1420,"wires":[["94c3a6b3.922108"]]},{"id":"a470cd92.fd24c","type":"inject","z":"b3b413d1.05b1b","name":"Add 10 mins","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":170,"y":1340,"wires":[["94c3a6b3.922108"]]}]
1 Like