For some lat/long pairs the hourAngle calculation throws NaN because a call to acos() has out of range input. Example:
var date = new Date("Wed, 22 May 2019 01:07:16 GMT");
var lat = 65;
var lng = 117.547923;
var times = SunCalc.getTimes(date, lat, lng);
for(var time in times){
var t = times[time];
console.log(time + " : " + t.toLocaleString());
}
result:
solarNoon : 5/21/2019, 11:07:51 PM
nadir : 5/21/2019, 11:07:51 AM
sunrise : 5/21/2019, 1:24:18 PM
sunset : 5/22/2019, 8:51:24 AM
sunriseEnd : 5/21/2019, 1:33:37 PM
sunsetStart : 5/22/2019, 8:42:06 AM
dawn : Invalid Date
dusk : Invalid Date
nauticalDawn : Invalid Date
nauticalDusk : Invalid Date
nightEnd : Invalid Date
night : Invalid Date
goldenHourEnd : 5/21/2019, 3:00:28 PM
goldenHour : 5/22/2019, 7:15:14 AM
This was my misunderstanding. Invalid Date will result from a location for which some of the times do not exist. At extreme latitude not all time-spans will be present.
For some lat/long pairs the hourAngle calculation throws NaN because a call to acos() has out of range input. Example:
result: solarNoon : 5/21/2019, 11:07:51 PM nadir : 5/21/2019, 11:07:51 AM sunrise : 5/21/2019, 1:24:18 PM sunset : 5/22/2019, 8:51:24 AM sunriseEnd : 5/21/2019, 1:33:37 PM sunsetStart : 5/22/2019, 8:42:06 AM dawn : Invalid Date dusk : Invalid Date nauticalDawn : Invalid Date nauticalDusk : Invalid Date nightEnd : Invalid Date night : Invalid Date goldenHourEnd : 5/21/2019, 3:00:28 PM goldenHour : 5/22/2019, 7:15:14 AM