Permalink
Browse files

Fix multiple date formats in Validation::date()

Fixes #2364
  • Loading branch information...
1 parent 4a1a46a commit 645ef47878380d2f80c21fdfb4d3d07ea28cd30c @markstory markstory committed Dec 13, 2011
Showing with 11 additions and 3 deletions.
  1. +10 −0 lib/Cake/Test/Case/Utility/ValidationTest.php
  2. +1 −3 lib/Cake/Utility/Validation.php
@@ -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
*
@@ -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;
}
}

0 comments on commit 645ef47

Please sign in to comment.