SunCalc
SunCalc copied to clipboard
Calculations for SUNSET, DUSK, NAUTIC_DUSK and ASTRO_DUSK produce identical results
Consider the following code:
function testSunsets() {
var sc = new SunCalc();
var location = [39.0, -77.0];
var now = Time.now();
location[0] = location[0] * 3.14159 / 180.0;
location[1] = location[1] * 3.14159 / 180.0;
System.println("SUNSET_START = " + sc.printMoment(sc.calculate(now, location, SUNSET_START)));
System.println("SUNSET = " + sc.printMoment(sc.calculate(now, location, SUNSET)));
System.println("BLUE_HOUR_PM = " + sc.printMoment(sc.calculate(now, location, BLUE_HOUR_PM)));
System.println("DUSK = " + sc.printMoment(sc.calculate(now, location, DUSK)));
System.println("NAUTIC_DUSK = " + sc.printMoment(sc.calculate(now, location, NAUTIC_DUSK)));
System.println("ASTRO_DUSK = " + sc.printMoment(sc.calculate(now, location, ASTRO_DUSK)));
}
The output I see is as follows:
SUNSET_START = 24.12.2023 19:00:00
SUNSET = 24.12.2023 19:00:00
BLUE_HOUR_PM = 24.12.2023 19:00:00
DUSK = 24.12.2023 19:00:00
NAUTIC_DUSK = 24.12.2023 19:00:00
ASTRO_DUSK = 24.12.2023 19:00:00
Am I being completely stupid, or are the various sunset types really returning the same moment, despite such seemingly large differences in sun angle?
Seemingly getting more reasonable values if I explicitly convert the input location to double-precision:
function calculate(moment, pos, what) {
var lat = pos[0].toDouble();
var lng = pos[1].toDouble();
Either way, THANK YOU for the library!