Skip to content
Permalink
Browse files

Make datetime validation objects.

Don't fail hard on objects getting into datetime validators.

Refs #10017
  • Loading branch information...
markstory committed Jan 12, 2017
1 parent 2adcead commit e7b4ccb1b3ae29ab7dc98fb1c5b78bb31d5f8466
Showing with 15 additions and 1 deletion.
  1. +9 −1 src/Validation/Validation.php
  2. +6 −0 tests/TestCase/Validation/ValidationTest.php
@@ -390,7 +390,9 @@ public static function date($check, $format = 'ymd', $regex = null)
if ($check instanceof DateTimeInterface) {
return true;
}
if (is_object($check)) {
return false;
}
if (is_array($check)) {
$check = static::_getDateString($check);
$format = 'ymd';
@@ -456,6 +458,9 @@ public static function datetime($check, $dateFormat = 'ymd', $regex = null)
if ($check instanceof DateTimeInterface) {
return true;
}
if (is_object($check)) {
return false;
}
$valid = false;
if (is_array($check)) {
$check = static::_getDateString($check);
@@ -507,6 +512,9 @@ public static function localizedTime($check, $type = 'datetime', $format = null)
if ($check instanceof DateTimeInterface) {
return true;
}
if (is_object($check)) {
return false;
}
static $methods = [
'date' => 'parseDate',
'time' => 'parseTime',
@@ -22,6 +22,7 @@
use Cake\Validation\Validation;
use Cake\Validation\Validator;
use Locale;
use stdClass;
require_once __DIR__ . '/stubs.php';
@@ -929,6 +930,11 @@ public function testDateTimeObject()
$this->assertTrue(Validation::time($dateTime));
$this->assertTrue(Validation::dateTime($dateTime));
$this->assertTrue(Validation::localizedTime($dateTime));
$this->assertFalse(Validation::time(new stdClass()));
$this->assertFalse(Validation::date(new stdClass()));
$this->assertFalse(Validation::dateTime(new stdClass()));
$this->assertFalse(Validation::localizedTime(new stdClass()));
}
/**

0 comments on commit e7b4ccb

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.