[
https://issues.apache.org/jira/browse/VALIDATOR-221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12468523
]
Carsten Drossel commented on VALIDATOR-221:
-------------------------------------------
I have a work-around (but I'm not very proud of it). When the date pattern
contains day and month only I add a leap year to the value. Like this:
if ( datePattern.contains( "d" ) && datePattern.contains( "M" ) &&
!datePattern.contains( y ) ) {
datePattern += "/yyyy";
value += "/2004";
}
... = GenericValidator.isDate( value, datePattern, true )
I don't think it's a defect in the implementation of the parse method of
DateFormat. Which Date should be returned for "02/29"? 03/01/1970 00:00?
02/29/1972 00:00? It's just bad luck that the year zero 1970 was not a leap
year.
> DateValidator considers "02/29" with format "MM/dd" invalid
> -----------------------------------------------------------
>
> Key: VALIDATOR-221
> URL: https://issues.apache.org/jira/browse/VALIDATOR-221
> Project: Commons Validator
> Issue Type: Bug
> Affects Versions: 1.3.1 Release
> Environment: Windows XP, Java 1.5.0_04
> Reporter: Carsten Drossel
> Priority: Minor
>
> When the date pattern contains only day and month the isValid(..)-method of
> DateValidator returns false for the value Feb. 29th.
> Here is a JUnit test that fails:
> public void testFebruary29th() throws Exception {
> assertTrue( DateValidator.getInstance().isValid( "02/29", "MM/dd", true ) );
> }
> The DateValidator uses the parse(..)-method of SimpleDateFormat for the
> validation. This method appears to complete any date using 01/01/1970 00:00.
> Since 1970 was not a leap year a ParseException is thrown for the input
> "02/29" with the format "MM/dd" because 02/29/1970 is not a valid date.
> But IMHO "02/29" should be valid. An example where it makes sense is a search
> for persons with a certain birthday.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]