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
This commit is contained in:
commit
429b18e28e
@ -93,10 +93,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
|||||||
// neither the native nor the stub IntlDateFormatter support
|
// neither the native nor the stub IntlDateFormatter support
|
||||||
// DateTimeImmutable as of yet
|
// DateTimeImmutable as of yet
|
||||||
if (!$value instanceof \DateTime) {
|
if (!$value instanceof \DateTime) {
|
||||||
$value = new \DateTime(
|
$value = new \DateTime($value->format('Y-m-d H:i:s.u e'));
|
||||||
$value->format('Y-m-d H:i:s.u e'),
|
|
||||||
$value->getTimezone()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $formatter->format($value);
|
return $formatter->format($value);
|
||||||
|
@ -53,10 +53,7 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe
|
|||||||
|
|
||||||
foreach ($comparison as $i => $value) {
|
foreach ($comparison as $i => $value) {
|
||||||
if ($value instanceof \DateTime) {
|
if ($value instanceof \DateTime) {
|
||||||
$comparison[$i] = new \DateTimeImmutable(
|
$comparison[$i] = new \DateTimeImmutable($value->format('Y-m-d H:i:s.u e'));
|
||||||
$value->format('Y-m-d H:i:s.u e'),
|
|
||||||
$value->getTimezone()
|
|
||||||
);
|
|
||||||
$add = true;
|
$add = true;
|
||||||
} elseif ('DateTime' === $value) {
|
} elseif ('DateTime' === $value) {
|
||||||
$comparison[$i] = 'DateTimeImmutable';
|
$comparison[$i] = 'DateTimeImmutable';
|
||||||
|
Reference in New Issue
Block a user