From 9def3ca79697a21c56bc24be9f0e4a35110c9d80 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Mon, 5 Jan 2015 10:48:34 +0100 Subject: [PATCH] Forcing ymd pattern in validation when an array is passed --- src/Validation/Validation.php | 10 ++++++++-- tests/TestCase/Validation/ValidationTest.php | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Validation/Validation.php b/src/Validation/Validation.php index 79e60d4d5f4..564e02a2494 100644 --- a/src/Validation/Validation.php +++ b/src/Validation/Validation.php @@ -309,7 +309,10 @@ public static function date($check, $format = 'ymd', $regex = null) 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 @@ public static function datetime($check, $dateFormat = 'ymd', $regex = null) 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); diff --git a/tests/TestCase/Validation/ValidationTest.php b/tests/TestCase/Validation/ValidationTest.php index 8897d6e00e2..98924bb5524 100644 --- a/tests/TestCase/Validation/ValidationTest.php +++ b/tests/TestCase/Validation/ValidationTest.php @@ -1493,6 +1493,9 @@ public function testDateArray() $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 @@ public function testDateTimeArray() 'meridian' => 'am' ]; $this->assertTrue(Validation::datetime($date)); + $this->assertTrue(Validation::datetime($date, 'mdy')); $date = [ 'year' => '2014', 'month' => '02', 'day' => '14',