Uploaded image for project: 'Commons Validator'
  1. Commons Validator
  2. VALIDATOR-221

DateValidator considers "02/29" with format "MM/dd" invalid

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.3.1 Release
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Windows XP, Java 1.5.0_04

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              drossel Carsten Drossel
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: