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 f49659f

Browse filesBrowse files
krzysiekpiaseckinicolas-grekas
authored andcommitted
[Validator] Support for DateTimeImmutable
1 parent eadfc93 commit f49659f
Copy full SHA for f49659f

File tree

Expand file treeCollapse file tree

4 files changed

+16
-2
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+16
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/DateTimeValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function validate($value, Constraint $constraint)
3030
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime');
3131
}
3232

33-
if (null === $value || '' === $value || $value instanceof \DateTime) {
33+
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
3434
return;
3535
}
3636

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/DateValidator.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__.'\Date');
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/DateTimeValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public function testDateTimeClassIsValid()
4242
$this->assertNoViolation();
4343
}
4444

45+
public function testDateTimeImmutableClassIsValid()
46+
{
47+
$this->validator->validate(new \DateTimeImmutable(), new DateTime());
48+
49+
$this->assertNoViolation();
50+
}
51+
4552
/**
4653
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
4754
*/

‎src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public function testDateTimeClassIsValid()
4242
$this->assertNoViolation();
4343
}
4444

45+
public function testDateTimeImmutableClassIsValid()
46+
{
47+
$this->validator->validate(new \DateTimeImmutable(), new Date());
48+
49+
$this->assertNoViolation();
50+
}
51+
4552
/**
4653
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
4754
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.