Integrated: 8367901: Calendar.roll(hour, 24) returns wrong result

Justin Lu jlu at openjdk.org
Mon Sep 22 17:01:54 UTC 2025


On Wed, 17 Sep 2025 22:37:52 GMT, Justin Lu <jlu at openjdk.org> wrote:

> 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

This pull request has now been integrated.

Changeset: ced3f13f
Author:    Justin Lu <jlu at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/ced3f13f4e036513444d1fea3958be11741c2b8e
Stats:     144 lines in 2 files changed: 141 ins; 0 del; 3 mod

8367901: Calendar.roll(hour, 24) returns wrong result

Reviewed-by: naoto, iris

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

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


More information about the core-libs-dev mailing list