mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Fix for suncalc for non UTC timezones
Thanks to @pmscientist
This commit is contained in:
parent
5b6cca1dd0
commit
7307891aee
@ -30,15 +30,12 @@ module.exports = function(RED) {
|
||||
|
||||
this.tick = setInterval(function() {
|
||||
var now = new Date();
|
||||
var hour = now.getUTCHours();
|
||||
var mins = now.getUTCMinutes();
|
||||
var times = SunCalc.getTimes(now, node.lat, node.lon);
|
||||
var hour1 = times[node.start].getUTCHours();
|
||||
var mins1 = times[node.start].getUTCMinutes();
|
||||
var hour2 = times[node.end].getUTCHours();
|
||||
var mins2 = times[node.end].getUTCMinutes();
|
||||
var e1 = (hour*60+mins) - (hour1*60+mins1);
|
||||
var e2 = (hour*60+mins) - (hour2*60+mins2);
|
||||
var nowMillis = Date.UTC(now.getUTCFullYear(),now.getUTCMonth(),now.getUTCDate(),now.getUTCHours(),now.getUTCMinutes());
|
||||
var startMillis = Date.UTC(times[node.start].getUTCFullYear(),times[node.start].getUTCMonth(),times[node.start].getUTCDate(),times[node.start].getUTCHours(),times[node.start].getUTCMinutes());
|
||||
var endMillis = Date.UTC(times[node.end].getUTCFullYear(),times[node.end].getUTCMonth(),times[node.end].getUTCDate(),times[node.end].getUTCHours(),times[node.end].getUTCMinutes());
|
||||
var e1 = nowMillis - startMillis;
|
||||
var e2 = nowMillis - endMillis;
|
||||
var moon = parseInt(SunCalc.getMoonIllumination(now).fraction*100+0.5)/100;
|
||||
var msg = { payload:0, topic:"sun", moon:moon };
|
||||
if ((e1 > 0) & (e2 < 0)) { msg.payload = 1; }
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name" : "node-red-node-suncalc",
|
||||
"version" : "0.0.5",
|
||||
"version" : "0.0.6",
|
||||
"description" : "A Node-RED node to provide a signal at sunrise and sunset",
|
||||
"dependencies" : {
|
||||
"suncalc" : "1.5.*"
|
||||
"suncalc" : "1.6.*"
|
||||
},
|
||||
"repository" : {
|
||||
"type":"git",
|
||||
|
Loading…
x
Reference in New Issue
Block a user