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

Calendar: error with multiple calls to set(field,value)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.2
    • core-libs
    • beta2
    • x86
    • windows_nt



      Name: rmT116609 Date: 09/28/2000


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)


      Several calls to java.util.Calendar.set(int field, int value) may lead to
      a wrong date, as shows the example below:

      public class TestCalendar {
          public static void main(String[] args){
              try {
                  test();
              } catch (Throwable e) {
                  e.printStackTrace();
              }
              try {
                  System.in.read();
              } catch (Throwable e) {
                  e.printStackTrace();
              }
          }
          public static void test(){
              Calendar cal = Calendar.getInstance();
              System.out.println("cal.getTime() = " + cal.getTime());
              cal.set(Calendar.WEEK_OF_YEAR,4);
              System.out.println("cal.set(Calendar.WEEK_OF_YEAR,4);");

              //(Uncommenting the next line cancels the bug:)
              //System.out.println("cal.getTime() = " + cal.getTime());

              cal.set(Calendar.DAY_OF_WEEK,2);
              System.out.println("cal.set(Calendar.DAY_OF_WEEK,2);");
              System.out.println("cal.getTime() = " + cal.getTime());
          }
      }

      It yields the result:

      cal.getTime() = Tue Sep 26 18:14:08 CEST 2000
      cal.set(Calendar.WEEK_OF_YEAR,4);
      cal.set(Calendar.DAY_OF_WEEK,2);
      cal.getTime() = Mon Sep 25 18:14:08 CEST 2000

      which is obviously not in week number 4.
      (Review ID: 110046)
      ======================================================================

            peytoia Yuka Kamiya (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: