JDK-8152077 : (cal) Calendar.roll does not always roll the hours during daylight savings changes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-03-15
  • Updated: 2020-08-20
  • Resolved: 2016-03-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9 Other
9 b113Fixed openjdk8u272Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
On the day of DST changes, Calendar.roll does not roll the hour 23. 
However, its javadoc states that it will "add a single unit of time".

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this snippet:

final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("CST"));
cal.setTimeInMillis(1457928024812l);

System.out.println(cal.getTime());
cal.roll(Calendar.HOUR_OF_DAY, true);
System.out.println(cal.getTime());


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output
Sun Mar 13 23:00:24 CDT 2016
Sun Mar 13 00:00:24 CDT 2016
ACTUAL -
Output:
Sun Mar 13 23:00:24 CDT 2016
Sun Mar 13 23:00:24 CDT 2016

REPRODUCIBILITY :
This bug can be reproduced always.


Comments
Not sure what work is needed, given this applies cleanly and both the new test & CalendarRegresson fail before and pass afterwards. Flagging with jdk8u-fix-request on Jonathan's behalf, approving and pushing.
20-08-2020

Jonathan Dowland <jdowland@redhat.com> is working on an OpenJDK 8u backport of this as it's a partial fix for JDK-8229922.
19-08-2020

When we pass TZ as "CST" the roll method does not change the date to Mar 14 00:00:24. However, when we pass TZ as "CDT" , the roll method changes the date and time as expected. Here is the sample output: Printing the date with CST timezone.. Sun Mar 13 23:00:24 CDT 2016 Sun Mar 13 23:00:24 CDT 2016 Printing the date with CDT timezone.. Sun Mar 13 23:00:24 CDT 2016 Mon Mar 14 00:00:24 CDT 2016
18-03-2016

The current roll() implementation is based on the internal UTC time. The new rolled UTC value is converted to the hour-related fields. At that time DST transitions cause problems. The roll operations should be performed based on wall-clock time.
18-03-2016