Cron plus -1 hour

Hi! Is there a way to make my cron plus activate an output minus 1 h ?
This is how it is set up:

[{"id":"e4f20e150336f746","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"872eb42d0fb54709","type":"cronplus","z":"e4f20e150336f746","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":546,"y":126,"wires":[[]]},{"id":"c2ed4f8861720be9","type":"function","z":"e4f20e150336f746","name":"Generate date event","func":"\n// create Dynamic Cron Schedule\nmsg.payload = {\n    \"command\": \"add\",\n    \"name\": \"Dynamic Cron Schedule\",\n    \"expression\": new Date(msg.payload.totalMinimumStartsAt),\n    \"expressionType\": \"dates\",\n    \"payload\": \"ON\",\n    \"payloadType\": \"str\",\n//    \"limit\": 1   \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":334,"y":126,"wires":[["872eb42d0fb54709"]]}]

"Move" to another time zone??

1 Like

In your Function node reference the Moment js library using the functionExternalModules option
you can read how to set that up here

image

and in code its easy to make datetime calculations ..

var time = moment.duration("01:00:00");  // time to subtract
var date = moment("2014-06-07 09:22:06");
node.warn(date);

msg.payload = date.subtract(time);

I can't really test because I don't know what your input is into the function node (its good practice to add an inject node with a sample of data to help with testing).
It's usually achieved in solar events by adding offset: "-60" to the dynamic object, but it may not work with cron events. Probably worth trying though?

Can't you just subtract 1 hour from the timestamp that you are generating in the function node?

I have a function node that calculates the lowess value and then i get a timestamp that look like this:
image

Is there a question there?

If you are asking how to subtract 1 hour from that, then in the function in the flow you posted where you have
new Date(msg.payload.totalMinimumStartsAt)
use
new Date(msg.payload.totalMinimumStartsAt).getTime() - 60 * 60 * 1000
That gives the timestamp in milliseconds, which I expect the node will be happy with. If not then add another new Date() round the whole thing, which will convert it back to a date.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.