Closed ghost closed 7 years ago
The documentation says:
- This will return null if there is no astronomical twilight. (Ex: no twilight in Antarctica in December)
You should check for null before using the return value. The library doesn't thow a NullPointerException
, but the code using the library (the System.out.println()
in this example) may result in an NPE if the return value is not checked.
I've added a unit test for this scenario:
testAstronomicalTwilight("UTC-5", "20160228", 82.50177764892578, -62.34809112548828, null, null);
The library is behaving as expected: returning null.
This website show Alert Canada being in an elongated astronomical twilight phase, yet your queries throws nulls... (http://suncalc.net/#/82.5018,-62.3481,4/2016.12.31/12:41) which app is wrong?
00:00—07:59 — night 07:59— n/a — astronomical twilight n/a — n/a — nautical twilight n/a — n/a — civil twilight n/a — n/a — sunrise n/a — n/a — daylight n/a — n/a — sunset n/a — n/a — civil twilight n/a — n/a — nautical twilight n/a —14:28 — astronomical twilight 14:28—00:00 — night
It looks like you tested this website for today, whereas the original issue was opened for a period at the end of February.
For February 28, that website reports:
00:00— n/a — night n/a —09:16 — astronomical twilight 09:16—12:27 — nautical twilight 12:27—16:27 — civil twilight 16:27— n/a — sunrise n/a — n/a — daylight n/a —18:19 — sunset 18:19—22:19 — civil twilight 22:19—01:30 — nautical twilight 01:30— n/a — astronomical twilight n/a —00:00 — night
Fantastic... so sorry about that... appears not to be an issue then.
Locations that are out of degree range throw null pointer exceptions
Alert, Nunavut, Canada throw null pointer exception Location: 82.50177764892578, -62.34809112548828
"At latitudes within 9 degrees of either Pole, as the sun's angular elevation difference is less than 18 degrees, twilight can last for the entire 24 hours. This occurs for one day at latitudes near 9 degrees from the Pole and extends up to several weeks the further towards the Pole one goes. The only permanent settlement to experience this condition is Alert, Nunavut, Canada, where it occurs for a week in late February, and again in late October." -- wikipedia
Consider throwing custom exceptions for these use cases versus null pointer exceptions.... or no exception at all. I'm a little confused as to what is the best functionality, but I don't think an exception should be thrown if there is no error... Wondering if there is a more optimal design overall.
Reference: http://suncalc.net/#/82.5018,-62.3481,6/2016.12.31/12:41