timeswitch, fix display status to local timezone.

to close #944
This commit is contained in:
Dave Conway-Jones 2022-08-22 10:27:49 +01:00
parent d913171f40
commit ecb2849675
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 6 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-timeswitch",
"version" : "0.2.0",
"version" : "0.2.1",
"description" : "A Node-RED node to provide a simple timeswitch to schedule daily on/off events.",
"dependencies" : {
"spacetime": "^6.16.3",

View File

@ -51,6 +51,7 @@ module.exports = function(RED) {
var today = Math.round((nowMillis - midnightMillis) / 60000) % 1440;
var starttime = Number(node.startt);
var endtime = Number(node.endt);
var tzOff = (new Date()).getTimezoneOffset();
if ((starttime >= 5000) || (endtime == 5000) || (endtime == 6000)) {
var times = SunCalc.getTimes(now, node.lat, node.lon);
@ -109,13 +110,11 @@ module.exports = function(RED) {
}
if (proceed >= 2) {
var duration = newendtime - today;
if (today > newendtime) { duration += 1440; }
//node.status({fill:"yellow",shape:"dot",text:"on for " + duration + " mins"});
node.status({fill:"yellow", shape:"dot", text:"on until " + parseInt(newendtime / 60) + ":" + ("0" + newendtime % 60).substr(-2)});
node.status({fill:"yellow", shape:"dot", text:"on until " + parseInt((newendtime -tzOff) / 60) + ":" + ("0" + (newendtime - tzOff) % 60).substr(-2)});
}
else {
node.status({fill:"blue", shape:"dot", text:"off until " + parseInt((starttime - tzOff) / 60) + ":" + ("0" + (starttime - tzOff) % 60).substr(-2)});
}
//else { node.status({fill:"blue",shape:"dot",text:"off"}); }
else { node.status({fill:"blue", shape:"dot", text:"off until " + parseInt(starttime / 60) + ":" + ("0" + starttime % 60).substr(-2)}); }
var msg = {};
if (node.mytopic) { msg.topic = node.mytopic; }