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

GregorianCalendar.add(int field, int amount) works wrong with field == YEAR

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2fcs
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



      Name: dfC67450 Date: 08/11/98



      If we add 12 months or 1 year to Feb-29-1996 we should obtain the same results.
      But products are different.

      Here is the test demonstrating the bug:
      ------------- Test.java -----------
      import java.util.*;

      public class Test {
          public static void main (String args[]){
            GregorianCalendar calendar = new GregorianCalendar(1996, 1, 29);
            System.out.println("init date: " + calendar.getTime());
            System.out.println();
            calendar.add(Calendar.MONTH, 12);
            Date date1 = calendar.getTime();
            System.out.println("after adding 12 months: " + date1);
            calendar = new GregorianCalendar(1996, 1, 29);
            calendar.add(Calendar.YEAR, 1);
            Date date2 = calendar.getTime();
            System.out.println("after adding one year : " + date2);
            if (date1.equals(date2)) {
              System.out.println("Test passed");
            } else {
              System.out.println("Test failed");
            }
          }
      }
      ---------Output from the test---------------------
      init date: Thu Feb 29 00:00:00 GMT+03:00 1996

      after adding 12 months: Fri Feb 28 00:00:00 GMT+03:00 1997
      after adding one year : Sat Mar 01 00:00:00 GMT+03:00 1997
      Test failed
      -------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              aliusunw Alan Liu (Inactive)
              Reporter:
              dfazunensunw Dmitri Fazunenko (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: