Timestamps under a node when activated seem to be stuck in GMT

I'm running the official docker in a VM, and have - /etc/localtime:/etc/localtime:ro set, but also added environment: - TZ=Australia/Melbourne just to try and rule that out (didn't help). I also run HassIO on another VM with the same parameters set. On both VM's, checking the date in the terminal returns the correct time and timezone, and exec'ing into the docker containers and checking the date is also correct, so it doesn't appear to be an issue at my end (though it still could be something else I suppose).

Debug timestamps in Node-RED are correct, it only seems to happen, as far as I can tell, when interacting with Homeassistant nodes.

Has anyone else seen this and know how to fix it? I imagine it'll be an issue if I try and do any time based automations...

What do you mean by "Timestamps under a node"? Is it some particular node?

Yep I think it only happens with HomeAssistant nodes. eg:

Those times are all GMT, I'm in AEST.

That will be a specific issue with those nodes. They are responsible for providing the text that gets displayed. I suggest raising an issue against them so their maintainer can fix it.

No probs, I'll do that thanks :slight_smile:

By the way Nick, bloody great job with this. I've only been playing around with it for a week but I'm super impressed. Not just by the functionality, but also the polish and the user friendliness.

2 Likes

You can confirm the locale that the node red server is set to using this flow. The Debug node should show the local time in the browser, the warn statements in the function should show the timezone offset and the local time in the server.

[{"id":"1d778363.059135","type":"debug","z":"d7ff0732.2f81d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":525.5,"y":322,"wires":[]},{"id":"98c9671.b2fec98","type":"inject","z":"d7ff0732.2f81d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":184,"y":319,"wires":[["f2045e49.17b4e"]]},{"id":"f2045e49.17b4e","type":"function","z":"d7ff0732.2f81d8","name":"Date","func":"msg.payload = new Date()\nnode.warn(\"Timezone offset in server: \" + msg.payload.getTimezoneOffset())\nnode.warn(\"Local time in server: \" + msg.payload.toLocaleString())\nreturn msg;","outputs":1,"noerr":0,"x":346.5,"y":318,"wires":[["1d778363.059135"]]}]

@Colin odd, when I run your flow I get:

4/20/2019, 6:39:45 AM[node: Date](http://localhost:1880/#)function : (warn)
"Timezone offset in server: -120"
4/20/2019, 6:39:45 AM[node: Date](http://localhost:1880/#)function : (warn)
"Local time in server: 4/20/2019, 12:39:45 PM"
4/20/2019, 6:39:45 AM[node: e2356a6d.e0a7b8](http://localhost:1880/#)msg.payload : Date
"Sat Apr 20 2019 12:39:45 GMT+0200 (Central European Summer Time)" 

Yet if I go to https://www.w3schools.com/jsref/jsref_tolocalestring.asp I get the correct locale time:

Methinks the clock is wrong on your node red machine.

browser and NR running on same machine (macOS 10.13.6)

Is node-red running in a container of some sort?
What is the correct timezone for where you are?

I run NR from the terminal (i.e. node-red test.json)
correct time zone is america/New York

Just thought, is this running on Windows?
If you try, in the flow, toUTCString() does it give you correct UTC time?
It seems that node thinks it is UTC+2. If you are on Windows then perhaps node needs to be told what the TZ is.

runnng on a Mac
here is the debug with UTC added:
47%20AM
and I grabbed the code from w3schools

<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the date and time as a string.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var d = new Date();
  var n = d.toLocaleString();
  document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Stored it on my machine and run it and this is the result:
25%20AM

Crazy isn't it.

So it must be something about the mac. i just ran the flow on one of my Pi's nd it looks correct:
04%20AM

Hmmmm

Node is using the wrong time zone. When you run the javascript direct in the browser it is ok, it is only when node runs it (via node-red) that it is wrong.