mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
Allow date to be DateTime object
This commit is contained in:
parent
be9d21399c
commit
8aa6ad1c5d
@ -495,7 +495,13 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateDate($field, $value)
|
protected function validateDate($field, $value)
|
||||||
{
|
{
|
||||||
return strtotime($value) !== false;
|
$isDate = false;
|
||||||
|
if($value instanceof \DateTime) {
|
||||||
|
$isDate = true;
|
||||||
|
} else {
|
||||||
|
$isDate = strtotime($value) !== false;
|
||||||
|
}
|
||||||
|
return $isDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -413,6 +413,13 @@ class ValidateTest extends BaseTestCase
|
|||||||
$this->assertTrue($v->validate());
|
$this->assertTrue($v->validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDateValidWithDateTimeObject()
|
||||||
|
{
|
||||||
|
$v = new Validator(array('date' => new DateTime()));
|
||||||
|
$v->rule('date', 'date');
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
|
||||||
public function testDateInvalid()
|
public function testDateInvalid()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('date' => 'no thanks'));
|
$v = new Validator(array('date' => 'no thanks'));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user