Library returning civil twilight timings for a different day than what was asked for in alaska
avinash-zemoso opened this issue · 2 comments
commons-suncalc library version : 3.2.
Java version : 12.
Description
SunTimes times = SunTimes.compute()
.on(2020,6,18) //set today's date
.timezone(ZoneId.of("America/Anchorage"))// set timezone
.at( 64.90127423829784, -147.87481800058953) // set some alaska location
.twilight(SunTimes.Twilight.CIVIL)
.execute();
System.out.println("Civil sunrise morning: " + times.getRise() );
System.out.println("Civil sunset evening: " + times.getSet() );
Output:
Civil sunrise morning: 2020-07-27T02:13-08:00[America/Anchorage]
Civil sunset evening: 2020-07-27T01:44:44-08:00[America/Anchorage]
Expected behaviour
The library should provide civil twilight times for the above mentioned location and date. https://www.timeanddate.com/sun/usa/fairbanks?month=6&year=2020 mentions that civil twilight is b/n 00:46 and 02:58 for 18th June.
Actual behaviour
The library is returning civil twilight timings for 27th July rather than for today.
It might be because timeanddate is compensating the atmospheric refraction for civil twilight, while suncalc isn't. But I will have a deeper look at that this weekend.
I'm sorry that it took a bit longer than the weekend. The good news: There is no bug. The timeanddate.com output was confusing me, though.
Civil twilight is not a point in time, but a period. Morning civil twilight starts at getRise()
of Twilight.CIVIL
, and ends at getRise()
of Twilight.VISUAL
(the default). Evening civil twilight starts at getSet()
of Twilight.VISUAL
and ends at getSet()
of Twilight.CIVIL
.
In your code, you calculated the moment of transition between civil and nautical twilight. And this one is actually not happening on June 18th. The sun always stays above the civil twilight angle. So on that day, the civil twilight starts with sunset and ends with sunrise. You can use calculators like FAA's Twilight Calculator to confirm this.
So what you actually need is to use Twilight.VISUAL
. It will give you:
Sunset: 2020-06-18T00:49:34-08:00[America/Anchorage]
Sunrise: 2020-06-18T02:56:12-08:00[America/Anchorage]
Closing because suncalc is working as expected.