$moment() function in jsonata

Hi all,
I recently discovered that $moment() function is available in Jsonata expression.This is great to have it there.I stumbled upon an issue though and hope you may lend me a hand.

I am trying to subtract a variable duration from a date. The function signature in momentjs should be
moment(date).subtract(value,string).format("x")

when I do the same thing in Jsonata expression I cannot provide the chained function , that is subtract any variables. It works only if I hard coded the values
that is it does not work if I try
$moment(msg.payload).subtract(msg.somevalue,msg.aduration).format("x")

it works only if
$moment(msg.payload).subtract(1,"w").format("x")

so my question is : is it something I am doing wrong, or is it that chained methods are unsupported by the Jsonata function in node-red?
I am not really sure how does node-red add functions to the Jsonata library of functions..
@janvda
thank you

Hi @nileio

I think this is due to the way jsonata references message properties.

I think you'll find this works:

$moment($.payload).subtract($$.somevalue,$$.aduration).format("x")
1 Like

did not even cross my mind and indeed it is the solution! it worked beautifully.
Thanks for help @knolleary

1 Like