Using msg.ui_control to apply timezone offset to datetime object in ui-table

Hello,

I am a Node-RED and JS newbie that would greatly appreciate some assistance on a dashboard issue I am trying to solve.

I have some timestamps stored as UTC datetime objects that I would like to show in a ui-table column. This thread helped me apply my desired formatting to show in the table, but I cannot seem to get timezone offsetting to work. I can apply timezone offset using JSONata expressions, but not sure if there is a way to embed that into the msg.ui_control JSON. I have tried adding a "timezone" parameter to no avail:

{
    "tabulator": {
        "columns": [
            {
                "formatter": "datetime",
                "formatterParams": {
                    "inputFormat": "x",
                    "outputFormat": "DD. MMMM YYYY hh:mm:ss",
                    "invalidPlaceholder": "(invalid date)",
					"timezone": "Australia/Brisbane"
                },
                "title": "Last Seen",
                "field": "last_seen"
            }
        ]
    }
}

The tabulator documentation says the luxon.js library is required for date/time formatting but it seems the output formatting works with the built-in moment.js features. I am hoping there is a way to do the same for timezone offsets?

Thanks

As I understand it, moment will convert UTC timestamps to the local of the browser running it. The idea is that a timestamp right now would display in my timezone (America/New_York) but on your device it would use your timezone "Australia/Brisbane".

Remember, formatting the output is different than converting it to a different time zone. If you want it to display in a different timezone then yes, you will have to do what the tabulator documentation requires.

Thanks, I see...

Would this be a matter of installing luxon.js and importing it via functionGlobalContext in settings.js? I note that usually you would need to then do a global.get() in a function node, but since the dependency is in the ui-table node, how would that work?

I don't know since I've never done it. Give it a try and see what happens

Okay, I gave it a go. I was able call luxon functions in a function node by invoking the global context variable but unfortunately I cannot get ui-table itself to pick it up for applying timezone offsets. I tried using the formatterParams timezone parameter specified in the tabulator documentation and also tried calling luxon in a custom formatter function using global.get(). Neither seem to work and doing the latter actually breaks the entire ui_control message.

The (kind of annoying) workaround I have at the moment is to store my datetime in local time and convert it back to UTC when I need to pass it to somewhere else that is expecting UTC.

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