On Tue, 14 Mar 2023 22:16:45 GMT, Justin Lu <j...@openjdk.org> wrote:
> This PR fixes the bug which occurred when `Calendar.roll(WEEK_OF_YEAR)` > rolled into a minimal first week with an invalid `WEEK_OF_YEAR` and > `DAY_OF_WEEK` combo. > > For example, Rolling _Monday, 30 December 2019_ by 1 week produced _Monday, > 31 December 2018_, which is incorrect. This is because `WEEK_OF_YEAR` is > rolled from 52 to 1, and the original `DAY_OF_WEEK` is 1. However, there is > no Monday in week 1 of 2019. This is exposed when a future method calls > `Calendar.complete()`, which eventually calculates a `fixedDate` with the > invalid `WEEK_OF_YEAR` and `DAY_OF_WEEK` combo. > > To prevent this, a check is added for rolls into week 1, which determines if > the first week is minimal. If it is indeed minimal, then it is checked if > `DAY_OF_WEEK` exists in that week, if not, `WEEK_OF_YEAR` must be incremented > by one. > > After the fix, Rolling _Monday, 30 December 2019_ by 1 week produces _Monday, > 7 January 2019_ Although this issue applies to Gregorian Calendar, it appears it may also occur with a Japanese Calendar under the right circumstances. `{$$$ Failed: Rolled: "Sunday, 29 December 1" by 1 week, expecting: "Sunday, 5 May 1", but got: "Saturday, 5 January 31"}` The Reiwa era begins on May 1st, 2019. Rolling the last Sunday of 2019 by 1 week, one would expect the resultant date to be the first Sunday of the Reiwai period (the 5th of May, 2019). However, a completely wrong date is returned, and the calendar actually rolls back an era into Heisei. Looking into it further, as well as the other calendars ------------- PR: https://git.openjdk.org/jdk/pull/13031