Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e6cfa9a

Browse filesBrowse 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
Copy full SHA for e6cfa9a

File tree

2 files changed

+8
-1
lines changed
Filter options

2 files changed

+8
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/TimeValidator.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php
+7Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.