Skip to content

Commit

Permalink
Fix multiple date formats in Validation::date()
Browse files Browse the repository at this point in the history
Fixes #2364
  • Loading branch information
markstory committed Dec 13, 2011
1 parent 4a1a46a commit 645ef47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 10 additions & 0 deletions lib/Cake/Test/Case/Utility/ValidationTest.php
Expand Up @@ -1411,6 +1411,16 @@ public function testDateMyNumeric() {
$this->assertFalse(Validation::date('12 06', array('my')));
}

/**
* Test validating dates with multiple formats
*
* @return void
*/
public function testDateMultiple() {
$this->assertTrue(Validation::date('2011-12-31', array('ymd', 'dmy')));
$this->assertTrue(Validation::date('31-12-2011', array('ymd', 'dmy')));
}

/**
* testTime method
*
Expand Down
4 changes: 1 addition & 3 deletions lib/Cake/Utility/Validation.php
Expand Up @@ -306,9 +306,7 @@ public static function date($check, $format = 'ymd', $regex = null) {

$format = (is_array($format)) ? array_values($format) : array($format);
foreach ($format as $key) {
$regex = $regex[$key];

if (self::_check($check, $regex) === true) {
if (self::_check($check, $regex[$key]) === true) {
return true;
}
}
Expand Down

0 comments on commit 645ef47

Please sign in to comment.