ioBroker / ioBroker.javascript

Script engine for JavaScript and Blockly
MIT License
325 stars 120 forks source link

[Bug]: Astro times states are a day late #1504

Closed peterbonge closed 7 months ago

peterbonge commented 7 months ago

I'm sure that

Script type

-

The problem

The astro states (javascript.0.variables.astro) are always a day late. If I restart the adapter the states get the correct times, but the next day it's the same problem. The time stamps of the states are "00:00:01", so I think they just get set a little bit too early.

iobroker.current.log (in debug mode!)

No response

Version of nodejs

18.19.0

Version of ioBroker js-controller

5.0.19

Version of adapter

7.8.0

klein0r commented 7 months ago

Strange, since the script runs at 00:00:01.000. Tested

const suncalc = require('suncalc2');

const calcDate = new Date();
calcDate.setHours(0);
calcDate.setMinutes(0);
calcDate.setSeconds(1);

const times = suncalc.getTimes(calcDate, 51, 8);
console.log(`sunset: ${times['sunset'].toUTCString()}`);

sunset: Thu, 22 Feb 2024 16:56:01 GMT

const calcDate = new Date();
calcDate.setHours(1);
calcDate.setMinutes(0);
calcDate.setSeconds(1);

sunset: Fri, 23 Feb 2024 16:57:46 GMT

It's a bit strange, the returned sunset value changes from 00:29:17 to 00:29:18 o'clock

klein0r commented 7 months ago

https://www.suncalc.org/#/51,8,6/2024.02.23/09:33/1/3 calculates the sunset at 17:57:47

Got it...

const suncalc = require('suncalc2');

const calcDate = new Date('2024-02-22T23:00:01.000Z');
calcDate.setMinutes(0);
calcDate.setSeconds(0);

for (let i = 0; i < 24; i++) {
    calcDate.setHours(i);

    const times = suncalc.getTimes(calcDate, 51, 8);
    console.log(`${calcDate.toUTCString()} - sunset: ${times['sunset'].toUTCString()}`);
}
Thu, 22 Feb 2024 23:00:00 GMT - sunset: Thu, 22 Feb 2024 16:56:01 GMT
Fri, 23 Feb 2024 00:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 01:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 02:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 03:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 04:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 05:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 06:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 07:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 08:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 09:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 10:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 11:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 12:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 13:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 14:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 15:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 16:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 17:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 18:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 19:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 20:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 21:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT
Fri, 23 Feb 2024 22:00:00 GMT - sunset: Fri, 23 Feb 2024 16:57:46 GMT