Fix getUTCOffSet rounding for non-integer timezones#49
Open
guillerodriguez wants to merge 1 commit intomikereedell:masterfrom
Open
Fix getUTCOffSet rounding for non-integer timezones#49guillerodriguez wants to merge 1 commit intomikereedell:masterfrom
guillerodriguez wants to merge 1 commit intomikereedell:masterfrom
Conversation
SolarEventCalculator.getUTCOffSet() uses BigDecimal.divide(3600000, new MathContext(2)) to convert ZONE_OFFSET into fractional hours. This was introduced in commit 30f64ec to fix handling of zones with non-integer offsets, such as Asia/Kolkata (UTC +5:30). However, MathContext(2) caps the result to 2 *significant digits* (not "2 decimal places"), so timezones whose offset has more than 2 significant digits were rounded incorrectly. Examples: Asia/Kathmandu +5:45 (5.75) -> 5.8 (off by 3 min) Australia/Eucla +8:45 (8.75) -> 8.8 (off by 3 min) Pacific/Chatham +12:45 (12.75) -> 13 (off by 15 min) Australia/Lord_Howe +10:30 (10.5) -> 11 (off by 30 min) Fix by using the existing divideBy() helper instead. Fixes: mikereedell#48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SolarEventCalculator.getUTCOffSet() uses BigDecimal.divide(3600000, new MathContext(2)) to convert ZONE_OFFSET into fractional hours. This was introduced in commit 30f64ec to fix handling of zones with non-integer offsets, such as Asia/Kolkata (UTC +5:30).
However, MathContext(2) caps the result to 2 significant digits (not "2 decimal places"), so timezones whose offset has more than 2 significant digits were rounded incorrectly.
Examples:
Fix by using the existing divideBy() helper instead.
Fixes: #48