mikereedell / sunrisesunsetlib-java

Library for computing the sunrise/sunset from GPS coordinates and a date, in Java.
http://mikereedell.github.com/sunrisesunsetlib-java/
Apache License 2.0
299 stars 69 forks source link

Incorrect sunset date when it is after calculator timezone midnight #37

Open axl8713 opened 6 years ago

axl8713 commented 6 years ago

When calculating sunset time for a location in the western hemisphere, there is no 1-day shift for the sunset when it is after the midnight of the timezone used for the calculator.

Location location = new Location("39.9522222", "-75.1641667");
SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "UTC");
Calendar calendar = new GregorianCalendar(2018, 04, 18);
calculator.getOfficialSunriseCalendarForDate(calendar); // 2018-05-18T09:43
calculator.getOfficialSunsetCalendarForDate(calendar); // 2018-05-18T00:12 <--- should be 2018-05-19T00:12

On the other hand, the shift is considered for the eastern hemisphere.

Location location = new Location("39.9522222", "75.1641667");
SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "UTC");
Calendar calendar = new GregorianCalendar(2018, 04, 18);
calculator.getOfficialSunriseCalendarForDate(calendar); // 2018-05-17T23:42
calculator.getOfficialSunsetCalendarForDate(calendar); // 2018-05-18T14:10