Skip to content

Commit

Permalink
Add support for DateTimeImmutable
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Feb 10, 2015
1 parent 8615f24 commit 48b3aab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/Zend/Validator/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Zend\Validator;

use DateTime;
use DateTimeInterface;
use Traversable;

/**
Expand Down Expand Up @@ -127,7 +128,8 @@ public function isValid($value)
*/
protected function convertToDateTime($param, $addErrors = true)
{
if ($param instanceof DateTime) {
// @TODO: when minimum dependency will be PHP 5.5, we can only keep check against DateTimeInterface
if ($param instanceof DateTime || $param instanceof DateTimeInterface) {
return $param;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/ZendTest/Validator/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace ZendTest\Validator;

use DateTime;
use DateTimeImmutable;
use stdClass;
use Zend\Validator;

Expand Down Expand Up @@ -96,6 +97,15 @@ public function testBasic($input, $format, $result)
$this->assertEquals($result, $this->validator->isValid($input));
}

public function testDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('`DateTimeImmutable` is only supported in PHP >=5.5.0');
}

$this->assertTrue($this->validator->isValid(new DateTimeImmutable()));
}

/**
* Ensures that getMessages() returns expected default value
*
Expand Down

0 comments on commit 48b3aab

Please sign in to comment.