Skip to content

Fix adjustForDST to use actual DST savings#47

Open
guillerodriguez wants to merge 1 commit intomikereedell:masterfrom
guillerodriguez:fix/use-actual-dst-savings
Open

Fix adjustForDST to use actual DST savings#47
guillerodriguez wants to merge 1 commit intomikereedell:masterfrom
guillerodriguez:fix/use-actual-dst-savings

Conversation

@guillerodriguez
Copy link
Copy Markdown

@guillerodriguez guillerodriguez commented Apr 26, 2026

SolarEventCalculator.adjustForDST() always adds 1 hour during DST, but some timezones have different DST savings (for example, 2 hours in Antarctica/Troll, or 30 minutes in Australia/Lord_Howe).

Also, some timezones have changed their DST rules historically. So, compute DST savings as:

TimeZone.getOffset(millis) - TimeZone.getRawOffset()

which returns the actual value for the given timestamp, instead of TimeZone.getDSTSavings(), which would return the timezone's "current" or "default" DST savings.

Fixes: #18

SolarEventCalculator.adjustForDST() always adds 1 hour during DST,
but some timezones have different DST savings (for example, 2 hours
in Antarctica/Troll, or 30 minutes in Australia/Lord_Howe).

Also, some timezones have changed their DST rules historically.
So, compute DST savings as:

    TimeZone.getOffset(millis) - TimeZone.getRawOffset()

which returns the actual value for the given timestamp, instead of
TimeZone.getDSTSavings(), which would return the timezone's "current"
or "default" DST savings.

Fixes mikereedell#18
@guillerodriguez
Copy link
Copy Markdown
Author

Note: I added a test case to reproduce the original bug and validate the fix. Since adjustForDST() is currently private, the test exercises the bug indirectly through SunriseSunsetCalculator's public API. An alternative would be to make adjustForDST() package-private and have the test code call it directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant