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

No hour 0 on April 15 1990.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.4.2_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
      Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [版本 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      It is impossible to represent any minute between April 15 1990 00:00:00 to April 15 1990 01:00:00 using Calendar class.
      In addition if a Calendar object is set to April 14 1990 00:00:00 and the object is increased one day by invoking add(Calendar.DAY_OF_MONTH, 1), the result will be April 14 1990 23:00:00.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile the folloing code and

      java tt 04/14/1990

      //------------------------------------------------------------------------------------------
      import java.util.*;
      import java.text.*;

      public class tt
      {
      static void showCalendar(Calendar cal)
      {
      System.out.println( cal.get(Calendar.YEAR) + "/" +
      (cal.get(Calendar.MONTH) + 1)+ "/" +
      cal.get(Calendar.DAY_OF_MONTH) + "-" +
      cal.get(Calendar.HOUR_OF_DAY) + ":" +
      cal.get(Calendar.MINUTE) + ":" +
      cal.get(Calendar.SECOND) + "/" +
      cal.get(Calendar.DAY_OF_WEEK) + "-" +
      cal.getTimeZone().getID());
      }
      public static void main(String[] args)
      {
      try
      {
      DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
      Date d = df.parse(args[0]);
      Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("PRC"));
      cal.set(1990, 3, 15, 0, 59, 0);
      showCalendar(cal);
      cal.setTime(d);
      showCalendar(cal);
      cal.set(Calendar.HOUR_OF_DAY, 4);
      showCalendar(cal);
      cal.set(Calendar.HOUR_OF_DAY, 0);
      showCalendar(cal);
      cal.add(Calendar.DAY_OF_MONTH, 1);
      showCalendar(cal);
      cal.set(Calendar.HOUR_OF_DAY, 4);
      showCalendar(cal);
      cal.set(Calendar.HOUR_OF_DAY, 0);
      showCalendar(cal);
      }
      catch(Exception e)
      {
      }
      }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1990/4/15-0:59:0/1-PRC
      1990/4/14-0:0:0/7-PRC
      1990/4/14-4:0:0/7-PRC
      1990/4/14-0:0:0/7-PRC
      1990/4/15-0:0:0/7-PRC
      1990/4/15-4:0:0/7-PRC
      1990/4/15-0:0:0/7-PRC
      ACTUAL -
      1990/4/15-1:59:0/1-PRC
      1990/4/14-0:0:0/7-PRC
      1990/4/14-4:0:0/7-PRC
      1990/4/14-0:0:0/7-PRC
      1990/4/14-23:0:0/7-PRC
      1990/4/14-4:0:0/7-PRC
      1990/4/14-0:0:0/7-PRC

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;
      import java.text.*;

      public class tt
      {
      static void showCalendar(Calendar cal)
      {
      System.out.println( cal.get(Calendar.YEAR) + "/" +
      (cal.get(Calendar.MONTH) + 1)+ "/" +
      cal.get(Calendar.DAY_OF_MONTH) + "-" +
      cal.get(Calendar.HOUR_OF_DAY) + ":" +
      cal.get(Calendar.MINUTE) + ":" +
      cal.get(Calendar.SECOND) + "/" +
      cal.get(Calendar.DAY_OF_WEEK) + "-" +
      cal.getTimeZone().getID());
      }
      public static void main(String[] args)
      {
      try
      {
      DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
      Date d = df.parse(args[0]);
      Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("PRC"));
      cal.set(1990, 3, 15, 0, 59, 0);
      showCalendar(cal);
      cal.setTime(d);
      showCalendar(cal);
      cal.set(Calendar.HOUR_OF_DAY, 4);
      showCalendar(cal);
      cal.set(Calendar.HOUR_OF_DAY, 0);
      showCalendar(cal);
      cal.add(Calendar.DAY_OF_MONTH, 1);
      showCalendar(cal);
      cal.set(Calendar.HOUR_OF_DAY, 4);
      showCalendar(cal);
      cal.set(Calendar.HOUR_OF_DAY, 0);
      showCalendar(cal);
      }
      catch(Exception e)
      {
      }
      }
      }
      ---------- END SOURCE ----------
      ###@###.### 2005-2-11 02:10:10 GMT

            okutsu Masayoshi Okutsu
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: