JDK-4210209 : DateFormat does not parse Feb 29 2000
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.2.0
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-02-09
  • Updated: 1999-02-12
  • Resolved: 1999-02-12
Related Reports
Duplicate :  
Description

Name: bb33257			Date: 02/09/99


DateFormat does not parse Feb 29, 2000 when set to strict.
This is probably a problem in the underlying GregorianCalendar
class.

Test code:

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

public class feb29 {
    public static void main(String[] args) throws ParseException {
        String pattern = "MMM d, yyyy";
        DateFormat fmt = new SimpleDateFormat(
                pattern,
                new DateFormatSymbols(Locale.US));
        for (int i=0; i<2; ++i) {
            fmt.getCalendar().setLenient(i == 0);
            System.out.println("Lenient = " + (i == 0));
            Date d = new Date(2000-1900, Calendar.FEBRUARY, 29);
            String s = fmt.format(d);
            System.out.println(d + " x " + pattern +
                               " => " + s);
            ParsePosition pos = new ParsePosition(0);
            d = fmt.parse(s, pos);
            System.out.println(d + " <= " + pattern + " x " + s);
            System.out.println("Parse pos = " + pos);
        }
    }
}

Output:

Lenient = true
Tue Feb 29 00:00:00 PST 2000 x MMM d, yyyy => Feb 29, 2000
Tue Feb 29 00:00:00 PST 2000 <= MMM d, yyyy x Feb 29, 2000
Parse pos = java.text.ParsePosition[index=12,errorIndex=-1]
Lenient = false
Tue Feb 29 00:00:00 PST 2000 x MMM d, yyyy => Feb 29, 2000
null <= MMM d, yyyy x Feb 29, 2000
Parse pos = java.text.ParsePosition[index=0,errorIndex=12]
(Review ID: 53988)

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