Skip to content

Commit

Permalink
Forcing ymd pattern in validation when an array is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 5, 2015
1 parent f63f6be commit 9def3ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Validation/Validation.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Validation/ValidationTest.php
Expand Up @@ -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'));
}

/**
Expand All @@ -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',
Expand Down

0 comments on commit 9def3ca

Please sign in to comment.