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:
Nicolas Grekas 2019-12-10 09:11:51 +01:00
commit 429b18e28e
2 changed files with 2 additions and 8 deletions

View File

@ -93,10 +93,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
// neither the native nor the stub IntlDateFormatter support
// DateTimeImmutable as of yet
if (!$value instanceof \DateTime) {
$value = new \DateTime(
$value->format('Y-m-d H:i:s.u e'),
$value->getTimezone()
);
$value = new \DateTime($value->format('Y-m-d H:i:s.u e'));
}
return $formatter->format($value);

View File

@ -53,10 +53,7 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe
foreach ($comparison as $i => $value) {
if ($value instanceof \DateTime) {
$comparison[$i] = new \DateTimeImmutable(
$value->format('Y-m-d H:i:s.u e'),
$value->getTimezone()
);
$comparison[$i] = new \DateTimeImmutable($value->format('Y-m-d H:i:s.u e'));
$add = true;
} elseif ('DateTime' === $value) {
$comparison[$i] = 'DateTimeImmutable';