commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <j...@apache.org>
Subject [jira] Commented: (VALIDATOR-221) DateValidator considers "02/29" with format "MM/dd" invalid
Date Thu, 01 Feb 2007 07:49:05 GMT

    [ https://issues.apache.org/jira/browse/VALIDATOR-221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12469356
] 

Niall Pemberton commented on VALIDATOR-221:
-------------------------------------------

I don't disagree with any of the comments here - Gabriel makes a good point that using an
alternative such as regexp would be another way to implement a date validator - and I agree
with Carsten that it should work and understand his frustration that it doesn't. Given that
its built to depend on java DateFormat's parse unfortunately its limited by the weakness of
its implementation and Calendar. If there was a reasonable fix I would apply it - but I'd
rather avoid nasty hacks to solve this issue - since I think going down that route would be
never ending given the weaknesses of java's data handling. In defence of using DateFormat
to validate it seems to make sense to use the same mechanism that people generally use to
format a date as a String to subsequently parse and validate. Another alternative would be
to look at Joda Time[1] to create a data validator - although I was aiming for "dependency
free" in the routines package. Out of interest the author of Joda Time (commons committer
Stephen Colebourne) has just had his proposal for a date/time JSR[2] accepted (JSR 310) which
is motivated out of issues with java's date handling.

[1] http://joda-time.sourceforge.net/
[2] http://jcp.org/en/jsr/detail?id=310

> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message