mourner / suncalc

A tiny JavaScript library for calculating sun/moon positions and phases.
BSD 2-Clause "Simplified" License
3.1k stars 415 forks source link

GETTIMES returning invalid sunrise sunset even after correct inputs #146

Open Chetna124 opened 4 years ago

Chetna124 commented 4 years ago

var date = new Date('2020-06-11T20:24:46.426Z'); getTimes(date,'66.09639074589798','29.714674589159888');

Result: { solarNoon: 2020-06-11T10:02:13.573Z, nadir: 2020-06-10T22:02:13.573Z, sunrise: Invalid Date, sunset: Invalid Date, sunriseEnd: 2020-06-10T22:51:46.384Z, sunsetStart: 2020-06-11T21:12:40.761Z, dawn: Invalid Date, dusk: Invalid Date, nauticalDawn: Invalid Date, nauticalDusk: Invalid Date, nightEnd: Invalid Date, night: Invalid Date, goldenHourEnd: 2020-06-11T01:10:09.689Z, goldenHour: 2020-06-11T18:54:17.457Z }

Really not able to understand why.

scgrant327 commented 3 years ago

Agreed, seeing the same thing with: sunTimes = SunCalc.getTimes(new Date(), 30.5, -86.5)

dawn: Invalid Date {}
dusk: Invalid Date {}
goldenHour: Invalid Date {}
goldenHourEnd: Invalid Date {}
nadir: Mon Dec 14 2020 23:42:39 GMT-0600 (Central Standard Time) {}
nauticalDawn: Invalid Date {}
nauticalDusk: Invalid Date {}
night: Invalid Date {}
nightEnd: Invalid Date {}
solarNoon: Tue Dec 15 2020 11:42:39 GMT-0600 (Central Standard Time) {}
sunrise: Invalid Date {}
sunriseEnd: Invalid Date {}
sunset: Invalid Date {}
sunsetStart: Invalid Date {}
__proto__: Object
knut-forkalsrud commented 1 year ago

var date = new Date('2020-06-11T20:24:46.426Z'); getTimes(date,'66.09639074589798','29.714674589159888');

You are very close to the Polar circle, and also close to mid summer.

In the code, sunrise seems to be when the sun's elevation crosses -0.833 degrees.

var times = SunCalc.times = [
    [-0.833, 'sunrise',       'sunset'      ],
    [  -0.3, 'sunriseEnd',    'sunsetStart' ],
    [    -6, 'dawn',          'dusk'        ],
    [   -12, 'nauticalDawn',  'nauticalDusk'],
    [   -18, 'nightEnd',      'night'       ],
    [     6, 'goldenHourEnd', 'goldenHour'  ]
];

Looking at your coordinates, it appears the sun never got below that limit. You have in effect midnight sun.

times = SunCalc.getTimes(new Date('2020-06-11T20:24:46.426Z'),66.09639074589798,29.714674589159888);
SunCalc.getPosition(times.nadir, 66.09639074589798,29.714674589159888).altitude * 180 / Math.PI;
-0.8314978114031835