Skip to content

Commit 78eec73

Browse files
minor #34895 [Validator][ConstraintValidator] Stop passing unnecessary timezone argument to \DateTime (fancyweb)
This PR was merged into the 3.4 branch. Discussion ---------- [Validator][ConstraintValidator] Stop passing unnecessary timezone argument to \DateTime | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Since we format the \DateTimeImmutable with the "e" character, it uses this timezone identifier and do not consider the passed one. See https://www.php.net/manual/en/datetime.construct.php: > The $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00). Commits ------- 03dbcf8794 [Validator][ConstraintValidator] Stop passing unnecessary timezone argument to \DateTime
2 parents 9042349 + 53e4e2d commit 78eec73

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

ConstraintValidator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ protected function formatValue($value, $format = 0)
9393
// neither the native nor the stub IntlDateFormatter support
9494
// DateTimeImmutable as of yet
9595
if (!$value instanceof \DateTime) {
96-
$value = new \DateTime(
97-
$value->format('Y-m-d H:i:s.u e'),
98-
$value->getTimezone()
99-
);
96+
$value = new \DateTime($value->format('Y-m-d H:i:s.u e'));
10097
}
10198

10299
return $formatter->format($value);

Tests/Constraints/AbstractComparisonValidatorTestCase.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ protected static function addPhp5Dot5Comparisons(array $comparisons)
5353

5454
foreach ($comparison as $i => $value) {
5555
if ($value instanceof \DateTime) {
56-
$comparison[$i] = new \DateTimeImmutable(
57-
$value->format('Y-m-d H:i:s.u e'),
58-
$value->getTimezone()
59-
);
56+
$comparison[$i] = new \DateTimeImmutable($value->format('Y-m-d H:i:s.u e'));
6057
$add = true;
6158
} elseif ('DateTime' === $value) {
6259
$comparison[$i] = 'DateTimeImmutable';

0 commit comments

Comments
 (0)