Set the current timezone NR uses from Node-Red

We run NR as a snap on Ubuntu core 20. The OS is configured with timezone data and we offer a GUI for the user to set the timezone. If the current timezone is changed a restart for NR is required for it to start using this timezone. This practically means for our users to need to power-cycle which is easily forgotten.
We are thinking to implement a flow which regularly monitors etc/timezone to see if there is a change and then restart NR from the flow but of course this will be very disruptive for the other flows which are running. since NR can handle DST I would not expect taking the timezone directly causes serious problems. Is there a possibility to push the used timezone without needing a restart?

Can you give an example of something that needs a restart following zone change?

Also I am intrigued about why the system regularly has timezone changes. Is it a portable system of some sort?

I used this flow to debug the issue:

[{"id":"7a51dad2.97d45c","type":"inject","z":"31fa50e9.6a1698","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":600,"wires":[["1d53d758.918031","19149eda.8d3c09"]]},{"id":"1d53d758.918031","type":"function","z":"31fa50e9.6a1698","name":"new Date(msg.payload)","func":"msg.payload = new Date(msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":600,"wires":[["2744411a.290e26"]]},{"id":"2744411a.290e26","type":"debug","z":"31fa50e9.6a1698","name":"From inject","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":600,"wires":[]},{"id":"19149eda.8d3c09","type":"function","z":"31fa50e9.6a1698","name":"new Date()","func":"msg.payload = new Date()\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":680,"wires":[["745dd9da.406128"]]},{"id":"745dd9da.406128","type":"debug","z":"31fa50e9.6a1698","name":"From system","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":680,"wires":[]}]

This is what I get from the debug window

As you can see after a restart it does reflext the timezone correctly

The system is delivered with a standard timezone world wide so at first use the user has to set the local timezone. We have a function to do that simply by syncing tho the PC used for configuring (Webbased GUI) so the user is hardly noticing the timezone change. The documentation informs them to reboot after this change but you know who reads documentation :wink: They start testing and complain time trigger do not work

In the previous post with the debug screenshot, both the timestamps are showing the same time, so the first one is not actually wrong. Confusing, I agree.

Do you mean that with an inject node set to inject at a fixed time that it injects at the wrong time? If so then that is a known issue with the inject node. It also goes wrong if the time is changed after node-red starts running. If you use node-red-contrib-cron-plus you can avoid that issue I believe, though I have not actually tested it with changing zone.

You could also avoid the issue by making the script that syncs the time, force a restart of node-red.

You could also avoid the issue by making the script that syncs the time, force a restart of node-red

The timezone is set outside NR so it would need to inject the NR restart from there. Unfortunately we have no control on that part.

In the previous post with the debug screenshot, both the timestamps are showing the same time, so the first one is not actually wrong

The issue is it still uses the timezone GMT+1 in this example so if you set a trigger based on your GMT time in 1 minute it only trigger in ~23h If I could avoid restarting NR when the timezone change is detected and make NR use the new timezone setting it is I think a cleaner solution.

I don't understand what you mean by that. Do you mean an inject node set to inject at a particular time? As I said, there is a known issue with the inject node that also makes it misbehave if the time is changed after node-red is restarted. If I remember correctly this is down to a problem with one of the underlying libraries rather than node-red code. Are you running the latest version of node-red? It might have been fixed in the latest version of that library, I don't know. To test you would have to configure an inject node and see if it injects at the wrong time. The time shown in the debug pane is purely cosmetic, it is not incorrect.

A rather inelegant solution would be to have a flow that runs at startup and at every 10 minutes, for example, that checks if the timezone has changed since node-red was started. If it has then it could restart node-red.

As I said, there is a known issue with the inject node that also makes it misbehave if the time is changed after node-red is restarted.

We are running 2.1.4 thi is what I tested and it seems to work correctly I move the clock up to 6h back and forth, also a DST change is handled but of course there could be corner cases. this makes me worry more :frowning:

A rather inelegant solution would be to have a flow that runs at startup and at every 10 minutes, for example, that checks if the timezone has changed since node-red was started. If it has then it could restart node-red

This is what we are considering, could be personal but I consider restarting not elegant since it disturbs everting running. I guess I need to accept it :wink:

So apart from the cosmetic issue in the debug pane, what exactly is the problem?

I don't understand that. If something works correctly, why do you worry about corner cases?

So apart from the cosmetic issue in the debug pane, what exactly is the problem?
It doesn't not when changing the timezone :wink:

What doesn't not(e?) change?

Preparation:

  • Timezone set to CET, current system time is 8:55 on the NR system
  • Set an inject node to trigger at 8:00

A) This does not work:

  • Change the time zone to GMT, system time switched to 7:55 which we show in our GUI
  • The inject node does not trigger when the clock shows 8:00

B) This does work

  • Change the time zone to GMT, system time switched to 7:55 which we show in our GUI
  • Restart NR
  • The inject node triggers when the clock jumps to 8:00

C) This does trigger but at an for the user unexpected moment

  • Change the inject node to trigger at 9:00
  • Change the time zone to GMT, system time switched to 7:55 which we show in our GUI
  • Wait until the clock moves to 8:00, trigger is executed

Sorry, I misunderstood what you said earlier. When I asked earlier whether it worked with the latest node red and you said you had tested with 2.1.4 and it worked correctly I thought you meant you had upgraded and the inject node was now working correctly. Looking back at you post I now see that is not what you meant.

Have you tried with the latest node-red? Your A,B,C tests work ok for me with 2.2.2 (on linux and with nodejs 16.14.0).

@Colin thank you for checking this, we get NR from a partner but I can fo sure ask them to upgrade to this version.

What OS are you running on the node-red server?

Ubuntu core20

I tested it using Ubuntu desktop. I don't know if there is a difference in the time handling between the two. It would probably be worth getting your partner to supply nodejs 16 as I am. If that is not possible then I can drop back to 14 and test again if necessary.

@Colin thank you for all your support, I will start the discussion

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