Browse Source

Forcing ymd pattern in validation when an array is passed

Jose Lorenzo Rodriguez 11 years ago
parent
commit
9def3ca796
2 changed files with 12 additions and 2 deletions
  1. 8 2
      src/Validation/Validation.php
  2. 4 0
      tests/TestCase/Validation/ValidationTest.php

+ 8 - 2
src/Validation/Validation.php

@@ -309,7 +309,10 @@ class Validation
             return true;
         }
 
-        $check = is_array($check) ? static::_getDateString($check) : $check;
+        if (is_array($check)) {
+            $check = static::_getDateString($check);
+            $format = 'ymd';
+        }
 
         if ($regex !== null) {
             return static::_check($check, $regex);
@@ -371,7 +374,10 @@ class Validation
             return true;
         }
         $valid = false;
-        $check = is_array($check) ? static::_getDateString($check) : $check;
+        if (is_array($check)) {
+            $check = static::_getDateString($check);
+            $dateFormat = 'ymd';
+        }
         $parts = explode(' ', $check);
         if (!empty($parts) && count($parts) > 1) {
             $time = array_pop($parts);

+ 4 - 0
tests/TestCase/Validation/ValidationTest.php

@@ -1493,6 +1493,9 @@ class ValidationTest extends TestCase
         $this->assertTrue(Validation::date($date));
         $date = ['year' => 'farts', 'month' => 'derp', 'day' => 'farts'];
         $this->assertFalse(Validation::date($date));
+
+        $date = ['year' => 2014, 'month' => 2, 'day' => 14];
+        $this->assertTrue(Validation::date($date, 'mdy'));
     }
 
     /**
@@ -1511,6 +1514,7 @@ class ValidationTest extends TestCase
             'meridian' => 'am'
         ];
         $this->assertTrue(Validation::datetime($date));
+        $this->assertTrue(Validation::datetime($date, 'mdy'));
 
         $date = [
             'year' => '2014', 'month' => '02', 'day' => '14',