From 1fa92769376e9ecd7ee8a43370afeb4aa16b7e58 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 30 Dec 2016 11:57:12 +0100 Subject: [PATCH] support DateTimeInterface instances for times --- .../Component/Validator/Constraints/TimeValidator.php | 2 +- .../Validator/Tests/Constraints/TimeValidatorTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Constraints/TimeValidator.php b/src/Symfony/Component/Validator/Constraints/TimeValidator.php index e398c10a2600..3f0234b8b089 100644 --- a/src/Symfony/Component/Validator/Constraints/TimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TimeValidator.php @@ -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; } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php index 10ffe8770878..a22251d0ee3c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php @@ -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(); + } }