First, you can convert your timestamp to a date format of your choosing without using a function node; instead, use a Mutate node and the {{formatDate}} Handlebars helper.
In the Mutate node, select “Set a new value”. Then, in the Value Template, enter {{formatDate (multiply path.to.the.time.to.[0].convert 1000) 'kk:mm'}}
.
{{formatDate}} takes two arguments. The first is the value to format, which is your timestamp. We’re including a subhelper in here (the (multiply ...)
part) to convert your timestamp from seconds to milliseconds. Note that if your timestamp is already in milliseconds, I recommend keeping the multiply
subhelper in place but changing the 1000
to a 1
, just to ensure that your timestamp is cast to a number.
The second argument is the Moment.js format string for how you want the date displayed. I believe kk:mm
is what you want here based on the example you posted.
Then, in the Mutate node’s Destination Path, enter path.to.today.correctTime.time
to insert the mutated value here.
To answer your original question, when using a function node, yes, payload
must be included in your path (but not in any of the other nodes). But the reason you’re getting an error is you’re using Handlebars-style variable references in what is a straight Javascript editor. On top of that, you are not converting timeux
to a Date object before getting the hours and minutes out of it.
So, you should change this line …
var timeux = payload.path.to.the.time.to.[0].convert * 1000;
… to this (note the missing period before the [0]) …
`var timeux = new Date(payload.path.to.the.time.to[0].convert * 1000);
Now your date methods will work, and then to add goodTime
to your payload, just set a new property on the payload
object:
payload.goodTime = goodTime;