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

DateFormat parses 2/29/00 as 2/29/1900

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.1.4
    • core-libs
    • None
    • sparc
    • solaris_2.5.1



      Name: joT67522 Date: 10/14/97


      Running the enclosed code results in an IllegalArgumentException
      being thrown from GregorianCalendar.computeTime().

      Looks to be a defect in the yy->yyyy adjustment logic:
        
         - assume current century
         - parse date (calling cal.getTime())
         - if parsed date is outside century window,
           add 100 years.

      This means that the calendar is being asked to
      validate 29-Feb-1900, which is not valid.

      Suggest yy expansion be done *before* validation, as
      the year affects the valid field values.

      import java.text.*;
      import java.util.*;

      public class LeapTest {
        public static void main(String[] args) {
          DateFormat fmt = new SimpleDateFormat("M/d/yy");
          fmt.getCalendar().setLenient(false);
          try {
            System.out.println(fmt.parse("2/29/00"));
          }
          catch(ParseException e) { e.printStackTrace(); }
        }
      }
      ======================================================================

            bcbeck Brian Beck (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: