8000 feature #21106 [Validator] support DateTimeInterface instances for ti… · symfony/symfony@e6cfa9a · GitHub
[go: up one dir, main page]

Skip to content

Commit e6cfa9a

Browse files
committed
feature #21106 [Validator] support DateTimeInterface instances for times (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
2 parents cbcc6ca + 1fa9276 commit e6cfa9a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Symfony/Component/Validator/Constraints/TimeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function validate($value, Constraint $constraint)
4747
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time');
4848
}
4949

50-
if (null === $value || '' === $value || $value instanceof \DateTime) {
50+
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
5151
return;
5252
}
5353

src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,11 @@ public function getInvalidTimes()
9999
array('00:00:60', Time::INVALID_TIME_ERROR),
100100
);
101101
}
102+
103+
public function testDateTimeImmutableIsValid()
104+
{
105+
$this->validator->validate(new \DateTimeImmutable(), new Time());
106+
107+
$this->assertNoViolation();
108+
}
102109
}

0 commit comments

Comments
 (0)
0