Java Library, Calculate solar times like solar noon, sunrise, sunset, astronomical, nautical and civil dawn/dusks
This work is heavily inspired by https://github.com/caarmen/SunriseSunset. The fundamental changes are:
- requires Java 11+,
- usage of Java 8 Time API (
ZonedDateTime
instead ofCalendar
), - splitting return results of dawn and dusk and
- usage of
Optional
becauseEmpty
is a valid result for solar times.
Entrypoint is the API
. You can instatiate it via new API()
to retrieve the SolarTime
and SunStateChecker
endpoints.
final var api = new API();
final var solarTime = api.getSolarTime();
final var now = ZonedDateTime.now();
final var latitude = 51.449680;
final var longitude = 6.973370;
solarTime.calculateNauticalDawn(now, latitude, longitude)
.map(dateTime -> dateTime.withZoneSameInstant(ZoneId.systemDefault()))
.map(ZonedDateTime::toLocalDateTime)
.ifPresent(time -> LOGGER.info("Nautical Dawn: " + time));
INFO: Nautical Dawn: 2019-06-25T03:15:46
final var sunStateChecker = api.getSunStateChecker();
LOGGER.info("is 24-hour day: " + sunStateChecker.is24HourDayTime(now, latitude, longitude));
INFO: is 24-hour day: false
For more examples check the wiki