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

Javadoc is different with implementation of GregorianCalendar.roll(int, int)

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: dfC67450 Date: 05/29/98



      Javadoc says about java.util.Calendar.roll(int field, boolean up):

       When rolling on the month or Calendar.MONTH field, other fields like
       date might conflict and, need to be changed. For instance,
       rolling the month on the date 01/31/96 will result in 03/02/96.

      In current implementation of GreagorianCalendar rolling the month on
      the date 01/31/96 will result in 02/29/96.

      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, 0, 31);
            System.out.println("init date: " + calendar.getTime());
            calendar.roll(Calendar.MONTH, 1);
            System.out.println("after rolling on month: " + calendar.getTime());
          }
      }
      ---------Output from the test---------------------

      init date: Wed Jan 31 00:00:00 GMT+03:00 1996
      after rolling on month: Thu Feb 29 00:00:00 GMT+03:00 1996

      -------------------------------------------------

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: