Index: tests/Zend/Date/DateObjectTest.php =================================================================== --- tests/Zend/Date/DateObjectTest.php (revision 23659) +++ tests/Zend/Date/DateObjectTest.php (working copy) @@ -106,6 +106,13 @@ } catch (Zend_Date_Exception $e) { // success } + + try { + $date = new Zend_Date("12:d5:12", "HH:mm:ss"); + $this->fail("exception expected"); + } catch (Zend_Date_Exception $e) { + // success + } } /** Index: library/Zend/Locale/Format.php =================================================================== --- library/Zend/Locale/Format.php (revision 23659) +++ library/Zend/Locale/Format.php (working copy) @@ -755,7 +755,7 @@ return join($values); } - + /** * Parse date and split in named array fields * @@ -858,6 +858,24 @@ $am = false; } } + + $parse['length'][$hour] = 1; + if ((iconv_substr($format, $hour, 2) == 'HH')) { + $parse['length'][$hour] = 2; + } + $parse['length'][$min] = 1; + if ((iconv_substr($format, $min, 2) == 'mm')) { + $parse['length'][$min] = 2; + } + $parse['length'][$sec] = 1; + if ((iconv_substr($format, $sec, 2) == 'ss')) { + $parse['length'][$sec] = 2; + } + + if (!Zend_Locale_Format::_validateNumberString($number, $parse)) { + require_once 'Zend/Locale/Exception.php'; + throw new Zend_Locale_Exception("Date string '$date' is not valid."); + } // split number parts $split = false; @@ -1050,6 +1068,28 @@ } /** + * Validate the number string, only numeric values allowed + * + * @param string $number Date string + * @param array $parsedformat Parsed date format array + * + * @return boolean + */ + private static function _validateNumberString($number, $parsedformat) + { + foreach ($parsedformat as $key => $value) { + if (isset($parsedformat['length'][$key])) { + $part = iconv_substr($number, $key, $parsedformat['length'][$key]); + if (!is_numeric($part)) { + return false; + } + } + } + + return true; + } + + /** * Search $number for a month name found in $monthlist, and replace if found. * * @param string $number Date string (modified)