# Using $moment() in change node jsonata 'Test' results in an error

**URL:** https://discourse.nodered.org/t/using-moment-in-change-node-jsonata-test-results-in-an-error/37995
**Category:** General
**Created:** [25 December 2020 00:39 UTC](https://discourse.nodered.org/t/using-moment-in-change-node-jsonata-test-results-in-an-error/37995 "2020-12-25T00:39:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [25 December 2020 00:39 UTC](https://discourse.nodered.org/t/using-moment-in-change-node-jsonata-test-results-in-an-error/37995/1 "2020-12-25T00:39:34Z")

</div>

In the `change` node, if you are using JSONata and use the $moment() function and try to test it, you get an error

```auto
Error evaluating expression:
  Attempted to invoke a non-function

```

Bug (?) or is this just something you can't use in the 'Test' portion?

What I want to do is deal with an object in this format:

```auto
[
    {
        "time": 1608813423311,
        "humidity": 36.7
    },
    {
        "time": 1608813423511,
        "humidity": 35.5
    }
]

```

and return the times as hh:mm am/pm

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [25 December 2020 08:09 UTC](https://discourse.nodered.org/t/using-moment-in-change-node-jsonata-test-results-in-an-error/37995/2 "2020-12-25T08:09:12Z")

</div>

Hi  
try

```auto
payload ~> |[*]|{"time":$moment(time).tz("london/europe").format("hh:mm a")}|	

```

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [25 December 2020 08:15 UTC](https://discourse.nodered.org/t/using-moment-in-change-node-jsonata-test-results-in-an-error/37995/3 "2020-12-25T08:15:47Z")

</div>

> [@zenofmud](#):
>
> just something you can't use in the 'Test' portion?

That's it... We don't have the moment library loaded in the editor, so just like the context functions, you can't use it in the test panel

Should probably have a message display as we do for the context functions.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [25 December 2020 08:31 UTC](https://discourse.nodered.org/t/using-moment-in-change-node-jsonata-test-results-in-an-error/37995/4 "2020-12-25T08:31:39Z")

</div>

@E1cid thanks for the effort but that gives me a  
`"Invalid JSONata expression: Argument 1 of function undefined does not match function signature"`  
message. I'm just going to use a `function` so I'll be able to understand it in the future 🤪

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [25 December 2020 08:39 UTC](https://discourse.nodered.org/t/using-moment-in-change-node-jsonata-test-results-in-an-error/37995/5 "2020-12-25T08:39:50Z")

</div>

Strange, as working here

 ![Screenshot_20201225-083820](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/b/2ba49f75be4ea606b26b2940100801a4339c3090.png)

Try this flow

```auto
[{"id":"4c8fe74d.23b62","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{ \"time\": 1608813423311, \"humidity\": 36.7 }, { \"time\": 1608813423511, \"humidity\": 35.5 }]","payloadType":"json","x":160,"y":2380,"wires":[["6040a378.a42784","84c9d74a.048ca8"]]},{"id":"6040a378.a42784","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload ~> |[*]|{\"time\":$moment(time).tz(\"london/europe\").format(\"hh:mm a\")}|\t\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":2380,"wires":[["84c9d74a.048ca8"]]},{"id":"84c9d74a.048ca8","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":2280,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [25 December 2020 08:49 UTC](https://discourse.nodered.org/t/using-moment-in-change-node-jsonata-test-results-in-an-error/37995/6 "2020-12-25T08:49:46Z")

</div>

My bad, I put it in the wrong place in my flow after a `csv` node. it works great!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [8 January 2021 08:49 UTC](https://discourse.nodered.org/t/using-moment-in-change-node-jsonata-test-results-in-an-error/37995/7 "2021-01-08T08:49:52Z")

</div>

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