Skip to content

Commit

Permalink
feature #21106 [Validator] support DateTimeInterface instances for ti…
Browse files Browse the repository at this point in the history
…mes (xabbuh)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Validator] support DateTimeInterface instances for times

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

The same has already been done for the `Date` and `DateTime` constraints in #18759.

Commits
-------

1fa9276 support DateTimeInterface instances for times
  • Loading branch information
fabpot committed Jan 2, 2017
2 parents cbcc6ca + 1fa9276 commit e6cfa9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -47,7 +47,7 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time');
}

if (null === $value || '' === $value || $value instanceof \DateTime) {
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
return;
}

Expand Down
Expand Up @@ -99,4 +99,11 @@ public function getInvalidTimes()
array('00:00:60', Time::INVALID_TIME_ERROR),
);
}

public function testDateTimeImmutableIsValid()
{
$this->validator->validate(new \DateTimeImmutable(), new Time());

$this->assertNoViolation();
}
}

0 comments on commit e6cfa9a

Please sign in to comment.