Skip to content

Commit c71d8ab

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: [Intl] promote warnings to value errors on PHP 8 Fix CS DateTime validator support for trailing data
2 parents 0e961e4 + ff7f030 commit c71d8ab

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Constraints/DateTimeValidator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public function validate($value, Constraint $constraint)
5959
return;
6060
}
6161

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

Tests/Constraints/DateTimeValidatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,12 @@ public function getInvalidDateTimes()
136136
['Y-m-d H:i:s', '2010-01-01 00:00:60', DateTime::INVALID_TIME_ERROR],
137137
];
138138
}
139+
140+
public function testDateTimeWithTrailingData()
141+
{
142+
$this->validator->validate('1995-05-10 00:00:00', new DateTime([
143+
'format' => 'Y-m-d+',
144+
]));
145+
$this->assertNoViolation();
146+
}
139147
}

0 commit comments

Comments
 (0)