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 27f6e28

Browse filesBrowse files
Stefan Klefffabpot
authored andcommitted
DateTime validator support for trailing data
1 parent 400ab7c commit 27f6e28
Copy full SHA for 27f6e28

File tree

Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/DateTimeValidator.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public function validate($value, Constraint $constraint)
5757
return;
5858
}
5959

60+
if('+' === substr($constraint->format, -1)) {
61+
$errors['warnings'] = array_filter($errors['warnings'], function($warning) {
62+
return 'Trailing data' !== $warning;
63+
});
64+
}
65+
6066
foreach ($errors['warnings'] as $warning) {
6167
if ('The parsed date was invalid' === $warning) {
6268
$this->context->buildViolation($constraint->message)

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,12 @@ public function getInvalidDateTimes()
128128
['Y-m-d H:i:s', '2010-01-01 00:00:60', DateTime::INVALID_TIME_ERROR],
129129
];
130130
}
131+
132+
public function testDateTimeWithTrailingData()
133+
{
134+
$this->validator->validate('1995-05-10 00:00:00', new DateTime([
135+
'format' => 'Y-m-d+',
136+
]));
137+
$this->assertNoViolation();
138+
}
131139
}

0 commit comments

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