I have another anomaly when using JSONata in a change node, and it is to do with time/date objects (of course).
I am using a node-red-contrib-sun-event-trigger to produce a sunrise trigger, and also capture the days other sun related events. on start up it produces an object with several key:value pairs for the days event, with the value being a date string like "2026-05-12T20:48:34.671Z" which is ISO compatible. But when I try to convert this to a date number with $toMillis() in a change node I get the error.
Invalid JSONata expression: Argument 1 of function "toMillis" does not match function signature
The Jsonata statement works in try.json.org when tested against a copy of the data fed to the node.
I can convert it the date string with some JS in a function node (val is the date string)
else if (isValidDateString(val)) {
// If it's a valid date string, parse directly
millis = new Date(val.trim()).getTime();
}
else {
// Try to coerce to string and parse
let strVal = String(val).trim();
if (isValidDateString(strVal)) {
millis = new Date(strVal).getTime();
}
Here is the simplified flow that exhibits the behaviour.
[
{
"id": "e75342e810b228f7",
"type": "debug",
"z": "fb3b8eb733c0c5e0",
"name": "Discrete Event",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 860,
"y": 860,
"wires": []
},
{
"id": "0683c88ce677ce7a",
"type": "change",
"z": "fb3b8eb733c0c5e0",
"name": "",
"rules": [
{
"t": "set",
"p": "sunrise",
"pt": "msg",
"to": "$toMillis(payload.sunrise)",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 640,
"y": 860,
"wires": [
[
"e75342e810b228f7"
]
]
},
{
"id": "6627d82026f11d88",
"type": "switch",
"z": "fb3b8eb733c0c5e0",
"name": "",
"property": "payload.sunEvent",
"propertyType": "msg",
"rules": [
{
"t": "null"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 410,
"y": 960,
"wires": [
[
"3a8e0dd0848ee708",
"f50672bec3e58cfa",
"0683c88ce677ce7a",
"e75342e810b228f7"
],
[
"8ed74b07effbab9b"
]
]
},
{
"id": "bee2284c3912022b",
"type": "junction",
"z": "fb3b8eb733c0c5e0",
"x": 300,
"y": 960,
"wires": [
[
"0a11d8da95898da4",
"6627d82026f11d88"
]
]
},
{
"id": "792599f715b4c8b7",
"type": "sun-event-inject",
"z": "fb3b8eb733c0c5e0",
"name": "",
"latitude": "-35.31120",
"longitude": "149.68053",
"event": "sunrise",
"offset": "0",
"injectEventTimesAfterStartup": true,
"x": 210,
"y": 960,
"wires": [
[
"bee2284c3912022b"
]
]
},
{
"id": "70b8f91ff26d4635",
"type": "global-config",
"env": [],
"modules": {
"node-red-contrib-sun-event-trigger": "1.1.1"
}
}
]
Although I have a workaround that suits me using the function node and converting all date strings to millis when received, it has taken me a while to develop a work around what is I believe is a bug in JSONata implementation... is there something in the node-red-contrib-sun-event-trigger node output I cannot see the cause.
ta
