Is it possible to use `$moment.duration()` in JSONata?

I want to show uptime in humanized format: 168732000 -> 2 days

:x: Invalid JSONata expression:

$moment.duration(168732000).humanize()

:check_mark: It works:

$moment(168732000).to(0, true)

It seems that $moment.function() is not allowed in JSONata:

  • moment.duration()
  • moment.unix()
  • moment.months()
  • moment.weekdays()
  • moment.isMoment(obj)
  • moment.isDate(obj)

This is the documentation for JSONata date/time functions

and See this thread - Problems with JSONata in Node-RED

There should be a humanise node in the node-red-contrib-moment package.

It would appear that the duration function and its sub functions are not working in JOSNata. Tested on 4.1.8

This is because we expose the $moment() function, not the top level moment object that has the duration function hanging under it.

So to answer the question directly - no it isn't possible today.

Please considering raising an issue and we can look if its possible to add support. Although the whole moment library is no longer maintained so not sure how much we want to expand use of it if there are better alternatives.