Moment msg.outTz does not work

Hi,

I'm trying to dynamically set the outTz from an input node by msg.outTz, but seems like the moment node does not pick up the outTz, seems like it still uses the default timezone (probably from browser?)

Here are my code, no matter what timezone outTz has, it wont change

[
    {
        "id": "2c5752fea8ababd1",
        "type": "inject",
        "z": "b8212410faeba9d9",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "outTz",
                "v": "UTC",
                "vt": "str"
            },
            {
                "p": "inTz",
                "v": "Australia/Sydney",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "",
        "topic": "",
        "payload": "1745919002581",
        "payloadType": "str",
        "x": 1120,
        "y": 160,
        "wires": [
            [
                "e6f5211b91ce70fa"
            ]
        ]
    },
    {
        "id": "05dc9b47e23fa604",
        "type": "debug",
        "z": "b8212410faeba9d9",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1620,
        "y": 160,
        "wires": []
    },
    {
        "id": "e6f5211b91ce70fa",
        "type": "moment",
        "z": "b8212410faeba9d9",
        "name": "",
        "topic": "",
        "input": "payload",
        "inputType": "msg",
        "inTz": "''",
        "adjAmount": 0,
        "adjType": "days",
        "adjDir": "add",
        "format": "",
        "locale": "en-AU",
        "output": "payload",
        "outputType": "msg",
        "outTz": "''",
        "x": 1360,
        "y": 160,
        "wires": [
            [
                "05dc9b47e23fa604"
            ]
        ]
    }
]

Thanks for helping!

Why not do it direct in the change node using $moment function of JSONata.

Your input is already in utc as that is the epoch timestamp (1745919002581). you can set the timezone of the output using the tz() function of moment functions

[{"id":"2c5752fea8ababd1","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"outTz","v":"UTC","vt":"str"},{"p":"inTz","v":"Australia/Sydney","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"1745919002581","payloadType":"num","x":420,"y":4940,"wires":[["d317dc9e7eb1ba07"]]},{"id":"05dc9b47e23fa604","type":"debug","z":"d1395164b4eec73e","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":4940,"wires":[]},{"id":"d317dc9e7eb1ba07","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$moment($$.payload).tz($$.outTz)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":4940,"wires":[["05dc9b47e23fa604"]]}]
2 Likes

Just to say that the moment custom node hasn't had any updates in a long time now (mea culpa!). As already noted, you can use moment in JSONata these days or in a function node.

1 Like