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

eou: Discrepancy in Calendar classes in JDK 1.1.3 & 1.1.4

XMLWordPrintable



      Name: joT67522 Date: 11/12/97


      Problem Description:

      Construct 2 calendar objects using a date,
      year, month, hour, min, sec.

      Check if the calendar objects are same.

      In JDK 1.1.3, they are same ( which is what
      one would expect ), where as in JDK 1.1.4, they
      are different.

      The objects are different in JDK 1.1.4 because
      it seems that JDK supplies a millisecond value
      while in 1.1.3, JDK always supplied 0 as a millisecond
      value.

      We are having big problems because of this.

      1. Can someone explain what would be the correct behavior
         to expect from the Date and Calendar classes ?

      2. Is there a constructor which takes millisecond
         as an argument ?

      3. Does the Calendar object always "complete" every
         unspecified field ? If so, what is an exhaustive list
         of fields ? I had thought, hour min sec date month
         year, to be exhaustive...now, it looks like in 1.1.4
         you have added the millisecond field to the list.

      4. Doing a toString on the Calendar object or on a Date
         object does not show all fields, such as millisecond...
         I think, you should make sure that every field which is
         used to compute a precision of a time value, must
         be displayed to the user.

      Thanks,

      Debapriya Ray ( Deep )

      --------------------- code sample ----------------

      import java.util.*;
      import java.io.*;

      public class date
      {
       public static void main( String[] args )
       {
        GregorianCalendar cal1 = new GregorianCalendar();
        cal1.set( Calendar.YEAR, 1997 );
        cal1.set( Calendar.MONTH, 10 );
        cal1.set( Calendar.DATE, 11 );
        cal1.set( Calendar.HOUR, 10 );
        cal1.set( Calendar.MINUTE, 20 );
        cal1.set( Calendar.SECOND, 40 );

        System.out.println( " Cal1 = " + cal1.getTime().getTime() );
        System.out.println( " Cal1 time in ms = " + cal1.get(Calendar.MILLISECOND) );
        for( int k = 0; k < 100 ; k++ );

        GregorianCalendar cal2 = new GregorianCalendar();
        cal2.set( Calendar.YEAR, 1997 );
        cal2.set( Calendar.MONTH, 10 );
        cal2.set( Calendar.DATE, 11 );
        cal2.set( Calendar.HOUR, 10 );
        cal2.set( Calendar.MINUTE, 20 );
        cal2.set( Calendar.SECOND, 40 );

        System.out.println( " Cal2 = " + cal2.getTime().getTime() );
        System.out.println( " Cal2 time in ms = " + cal2.get(Calendar.MILLISECOND) );
        if( cal1.equals( cal2 ) )
      System.out.println(" Cal1 == Cal2 " );
        else
      System.out.println(" Cal1 != Cal2 " );

       }
      }

      ------------------- JDK 113 output ----------------
      compile and run using JDK 113:

       Cal1 = 879261640000
       Cal1 time in ms = 0
       Cal2 = 879261640000
       Cal2 time in ms = 0
       Cal1 == Cal2

      -------------------- JDK 114 output ---------------

       Cal1 = 879265240216
       Cal1 time in ms = 216
       Cal2 = 879265240246
       Cal2 time in ms = 246
       Cal1 != Cal2
      (Review ID: 20021)
      ======================================================================

            aliusunw Alan Liu (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: