Needing help with formatting j$ things

Sorry folks.

I can't seem to get it.

I have this:

[
    {
        "id": "b5fa13f755ec33fe",
        "type": "change",
        "z": "235f16ee6e459f2c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$moment().tz(\"Australia/Sydney\").format(\"H:m:s\")",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$split($$.payload, \":\").$formatInteger($number($), \"w\")",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 4180,
        "y": 3550,
        "wires": [
            []
        ]
    }
]

Which is good. It works.

BUT - yeah, there is one.

I would also like to get the time (hours minutes seconds) as integer numbers as/in another part of the message.

So, say msg.time.
(Can be an array or structure.)

Just I need to so stuff at/in the next node and it would be easier if I had the numeric values rather than the text values - which are still needed.

Worked it out - eventually.

This code did the trick.

let x = msg.time.split(":")

msg.hour   = parseInt(x[0])
msg.minute = parseInt(x[1])
msg.second = parseInt(x[2])

//------------------
//      New stuff added 2024 06 08
if (msg.hour < 10)
{
    // less than 10.  Add leading *zero*
    node.warn("hour")
    msg.hour = "zero " + msg.payload[0]
}


if (msg.minute < 10)
{
    // less than 10.  Add leading *zero*
    node.warn("minute")
    msg.minute = "zero " + msg.minute
}

if (msg.second < 10)
{
    // less than 10.  Add leading *zero*
    node.warn("second")
    msg.second = "zero " + msg.payload[2]
}

//------------------


if (msg.minute == 0)
{
    msg.minute = " hundred "
    //return msg;
}

if (msg.second == 0)
{
    msg.second = "exactly"
} else
msg.second = "and " + msg.second + " seconds"

return msg;

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