You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@ CHANGELOG
8
8
* added option `alpha3` to `Country` constraint
9
9
* allow to define a reusable set of constraints by extending the `Compound` constraint
10
10
* added `Sequentially` constraint, to sequentially validate a set of constraints (any violation raised will prevent further validation of the nested constraints)
11
+
* added support to validate `\DateInterval` instances with relative string date formats in the `Range` and all comparisons constraints
@@ -74,13 +78,22 @@ public function validate($value, Constraint $constraint)
74
78
} catch (\Exception$e) {
75
79
thrownewConstraintDefinitionException(sprintf('The compared value "%s" could not be converted to a "%s" instance in the "%s" constraint.', $comparedValue, $dateTimeClass, \get_class($constraint)));
thrownewConstraintDefinitionException(sprintf('The compared value "%s" could not be converted to a "DateTimeImmutable" instance in the "%s" constraint.', $comparedValue, \get_class($constraint)));
89
+
}
77
90
}
78
91
79
92
if (!$this->compareValues($value, $comparedValue)) {
// Convert strings to DateTimes if comparing another DateTime
60
-
// This allows to compare with any date/time value supported by
61
-
// the DateTime constructor:
62
-
// https://php.net/datetime.formats
60
+
$minIsDateIntervalComparison = false;
61
+
$maxIsDateIntervalComparison = false;
62
+
63
63
if ($valueinstanceof \DateTimeInterface) {
64
+
// Convert strings to DateTimes if comparing another DateTime
65
+
// This allows to compare with any date/time value supported by
66
+
// the DateTime constructor:
67
+
// https://php.net/datetime.formats
68
+
64
69
$dateTimeClass = null;
65
70
66
71
if (\is_string($min)) {
@@ -82,16 +87,37 @@ public function validate($value, Constraint $constraint)
82
87
thrownewConstraintDefinitionException(sprintf('The max value "%s" could not be converted to a "%s" instance in the "%s" constraint.', $max, $dateTimeClass, \get_class($constraint)));
thrownewConstraintDefinitionException(sprintf('The max value "%s" could not be converted to a "DateTimeImmutable" instance in the "%s" constraint.', $max, \get_class($constraint)));
thrownewConstraintDefinitionException(sprintf('The min value "%s" could not be converted to a "DateTimeImmutable" instance in the "%s" constraint.', $min, \get_class($constraint)));
Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,8 @@ public function provideValidComparisons(): array
38
38
['0', '0'],
39
39
['333', '0'],
40
40
[null, 0],
41
+
['30 >= 0' => new \DateInterval('PT30S'), 0],
42
+
['0 >= 0' => new \DateInterval('PT0S'), 0],
41
43
];
42
44
}
43
45
@@ -46,10 +48,14 @@ public function provideValidComparisons(): array
46
48
*/
47
49
publicfunctionprovideInvalidComparisons(): array
48
50
{
51
+
$negativeDateInterval = new \DateInterval('PT45S');
0 commit comments