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...
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.
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.
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"]]}]
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.
<!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:
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.