Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8367901

Calendar.roll(hour, 24) returns wrong result

XMLWordPrintable

    • Cause Known
    • 11
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Mon Sep 12 15:30:45 GMT 2005 roll(HOUR,24) get Mon Sep 12 16:30:45 GMT 2005.
      I think the correct result should be Mon Sep 12 15:30:45 GMT 2005.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Mon Sep 12 15:30:45 GMT 2005
      Mon Sep 12 14:30:45 GMT 2005
      Mon Sep 12 15:30:45 GMT 2005
      Mon Sep 12 15:30:45 GMT 2005
      ACTUAL -
      Mon Sep 12 15:30:45 GMT 2005
      Mon Sep 12 14:30:45 GMT 2005
      Mon Sep 12 15:30:45 GMT 2005
      Mon Sep 12 16:30:45 GMT 2005

      ---------- BEGIN SOURCE ----------


      import java.util.GregorianCalendar;
      import static java.util.Calendar.HOUR;
      import java.util.Locale;
      import java.util.TimeZone;

      public class DateRollTest{
          public static void main(String[] args) {
              TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
              GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US);
              cal.clear();
              cal.set(2005, 8, 12, 15, 30, 45);
              System.out.println(cal.getTime());
              cal.roll(HOUR, 23);
              System.out.println(cal.getTime());


              cal.clear();
              cal.set(2005, 8, 12, 15, 30, 45);
              System.out.println(cal.getTime());
              cal.roll(HOUR, 24);
              System.out.println(cal.getTime());
          }

      }
      ---------- END SOURCE ----------

            jlu Justin Lu
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: