RFR: 8367901: Calendar.roll(hour, 24) returns wrong result [v3]

Justin Lu jlu at openjdk.org
Thu Sep 18 22:31:17 UTC 2025


> Please review this PR which addresses an edge case for `GregorianCalendar.roll(int, int)` when the rolled amount would cause the hour to remain the same as before the call. After this change, the expected hour is returned. That is, rolling a full cycle for HOUR (12 hours) and HOUR_OF_DAY (24 hours) should keep the hour the same as before the call.
> 
> For example, a calendar with HOUR_OF_DAY == 15,
> 
> 
> cal.roll(Calendar.HOUR_OF_DAY, 23);
> cal.get(Calendar.HOUR_OF_DAY); // returns 14
> 
> 
> cal.roll(Calendar.HOUR_OF_DAY, 24);
> // Incorrectly returns 16. A full cycle is expected to return the starting hour (15)
> cal.get(Calendar.HOUR_OF_DAY); 
> 
> 
> cal.roll(Calendar.HOUR_OF_DAY, 25);
> cal.get(Calendar.HOUR_OF_DAY); // returns 16

Justin Lu has updated the pull request incrementally with one additional commit since the last revision:

  savings -> saving

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/27355/files
  - new: https://git.openjdk.org/jdk/pull/27355/files/9316ca62..b4a34084

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=27355&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=27355&range=01-02

  Stats: 5 lines in 1 file changed: 0 ins; 0 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/27355.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27355/head:pull/27355

PR: https://git.openjdk.org/jdk/pull/27355


More information about the core-libs-dev mailing list