How can i sum in one hour the msg.payload["2"]: "13:00". Like if 1: "13:00", 2 must be "14:00"
I'm a little confused by your description... Is your goal to end up with this?
Yes, but its a generic case. I want to sum in one hour my 1 and put in the 2
Anyone else got ideas?
You can do simple time and date calculations with node-red-contrib-moment. This has the advantage of being able to deal with the complexities of summertimes, timezones, leapyears and other date oddities.
You can also use JSONata though I think you have to have the input in ISO format then convert to milliseconds. Perhaps not so good.
If you only want hours and can drop the minutes, then just use the time as a string, split on ":" and take the first element of the result as an integer.
I dont know if is a string or time but when i sum 13:00 + 1 the result is 13:001.
What happens at "23:00" -- the next one should be "00:00"?
I would try using Julian's suggestion and install
node-red-contrib-moment... use a
change node to pull out element 1, use the
moment node to convert to a datetime and offset by 1 hour, then use another
change node to put the time back into your payload element 2.
Alternately, you could use some primitive JS code, like so (not fully tested):
var ts = "1970-01-01 " + msg.payload; // build an epoch datetime var ms = Date.parse(ts)+3600000; // add 1 hour in milliseconds var tm = new Date(ms).toTimeString(); // convert to time string msg.payload = tm.substring(0,5); return msg;
Where are you getting the times from?
Well, my project will start at 8:00 and finish at 19:00.
I made a integration with watson assistant, so the time e get from there. My msg.payload contains intents,the time is one of this intents and came like this: "13:00"
I think this will help. The arrow from up its my msg.payload before the function with name verifica horário/data/colaborador. I do the treatment of my variables in the lines 23 and 31, and the arrow bellow its my msg.payload after the function.