compare week-year not calendar year in compareWeeks#408
Open
sahvx655-wq wants to merge 1 commit into
Open
Conversation
AbstractCalendarValidator.compare ordered WEEK_OF_YEAR on Calendar.YEAR, but a week belongs to its week-year, which differs from the calendar year at the year boundary, so compareWeeks treated 31 Dec and 1 Jan of the same calendar year as the same week. Compare the week-year (getWeekYear, falling back to YEAR when week dates are unsupported) before the week number.
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.
compareWeeks reports 31 December and 1 January of the same calendar year as the same week. AbstractCalendarValidator.compare orders the WEEK_OF_YEAR field on Calendar.YEAR and then WEEK_OF_YEAR, but a week belongs to its own week-year, and at the turn of the year that week-year differs from the calendar year. Under the US locale 31 Dec 2018 has WEEK_OF_YEAR 1 and a week-year of 2019, so against 1 Jan 2018 (also WEEK_OF_YEAR 1) the year and the week number both match and two dates roughly 52 weeks apart compare equal. The mirror case fails the other way: 31 Dec 2018 and 1 Jan 2019 share week 1 of week-year 2019 yet compare as different weeks because their calendar years differ.
The fix orders the WEEK_OF_YEAR comparison on the week-year from Calendar.getWeekYear(), falling back to Calendar.YEAR where the calendar does not support week dates, before comparing the week number, and leaves every other field untouched. compareQuarters already shifts its year at the quarter boundary, so this keeps the week comparison consistent with it. The added test fails on the current code and passes with the change.
mvn; that'smvnon the command line by itself.