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

adjustForDST ignores timezone.getDSTSavings (and uses a constant offset of 1hr) #18

Open forrestguice opened 7 years ago

forrestguice commented 7 years ago

I have a couple unusual TimeZone objects that I am having trouble using with the library. I've traced my issue to SolarEventCalculator.adjustForDST - when inDaylightTime it assumes a constant offset of 1hr.

  1. My first unusual TimeZone uses daylight savings but applies an offset other than an hour - its getDSTSavings() method returns an arbitrary value.
  2. My second unusual TimeZone uses daylight savings but applies a dynamic offset that depends on the date - its always inDaylightTime, its getOffset(long date) is different depending on date, and its getDSTSavings() value is completely ignored. I'm sure that breaks a whole slew of rules (but thats the way this TimeZone object works).

For the first I think the fix is to add the value of getDSTSavings (converted from ms to hours) instead of adding BigDecimal.ONE.

For the second I think the fix is to replace getDSTSavings (or 1hr) with the value of getOffset(date) - getRawOffset (converted from ms to hours), which shouldn't change anything for normal timezones (the difference will equal getDSTSavings), but should allow the unusual TimeZone to work right.

I'll also submit a pull request. Maybe the second type of timezone isn't worth accommodating, but I am thinking adjustForDST should at least use getDSTSavings instead of BigDecimal.ONE.