I'm having an issue with Zend_Date (and, by extension, Zend_Validate_Date)
that would seem to qualify as "unexpected behavior", but I'm not sure if
it's legitimately unexpected or if it's my expectations that are out of
whack.

First off, some basic information: I'm seeing this issue in ZF 1.11.3 on a
FreeBSD 6.4 system with PHP 5.2.14. Ultimately, I'm using Zend_Validate_Date
to validate date inputs from a form (e.g. date of birth).

Given this code...

<?php

require 'Zend/Debug.php';
require 'Zend/Locale/Format.php';

Zend_Debug::dump( Zend_Locale_Format::getDate( '123', array(
    'date_format' => 'd.M.y',
    'format_type' => 'iso',
    'fix_date' => false
) ) );

?>

...I would expect it to be unable to parse "123" as a date, since it doesn't
follow the specified format. Unfortunately, I get the following output:

array(5) {
  ["date_format"] => string(5) "d.M.y"
  ["locale"] => string(5) "en_US"
  ["day"] => string(2) "12"
  ["month"] => string(1) "3"
  ["year"] => bool(false)
}

This is a problem, because Zend_Validate_Date considers this a valid date.

<?php

require 'Zend/Debug.php';
require 'Zend/Validate/Date.php';

$validator = new Zend_Validate_Date( array(
    'format' => 'd.M.y'
) );

Zend_Debug::dump( $validator->isValid( '123' ) );

?>

Output:

bool(true)

Now, if I use a value of "12.3" instead of "123", I get expected output:

array(4) {
  ["date_format"] => string(5) "d.M.y"
  ["locale"] => string(5) "en_US"
  ["day"] => string(2) "12"
  ["month"] => string(1) "3"
}

bool(false)

So... is what I've described above expected behavior and I'm just doing it
wrong, or is it a legitimate bug?

(Either way, I suppose I'll need to throw Zend_Validate_Regex into the mix
to make sure the input is in the correct format.)

Thanks in advance,
Ryan Lange

Reply via email to