Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/serializer/Normalizer/DateTimeNormalizer.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children | af1871eacc83 |
line wrap: on
line diff
--- a/vendor/symfony/serializer/Normalizer/DateTimeNormalizer.php Tue Jul 10 15:07:59 2018 +0100 +++ b/vendor/symfony/serializer/Normalizer/DateTimeNormalizer.php Thu Feb 28 13:21:36 2019 +0000 @@ -28,11 +28,11 @@ private $format; private $timezone; - private static $supportedTypes = array( + private static $supportedTypes = [ \DateTimeInterface::class => true, \DateTimeImmutable::class => true, \DateTime::class => true, - ); + ]; /** * @param string $format @@ -49,7 +49,7 @@ * * @throws InvalidArgumentException */ - public function normalize($object, $format = null, array $context = array()) + public function normalize($object, $format = null, array $context = []) { if (!$object instanceof \DateTimeInterface) { throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".'); @@ -59,7 +59,8 @@ $timezone = $this->getTimezone($context); if (null !== $timezone) { - $object = (new \DateTimeImmutable('@'.$object->getTimestamp()))->setTimezone($timezone); + $object = clone $object; + $object = $object->setTimezone($timezone); } return $object->format($format); @@ -78,7 +79,7 @@ * * @throws NotNormalizableValueException */ - public function denormalize($data, $class, $format = null, array $context = array()) + public function denormalize($data, $class, $format = null, array $context = []) { $dateTimeFormat = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : null; $timezone = $this->getTimezone($context); @@ -88,7 +89,7 @@ } if (null !== $dateTimeFormat) { - if (null === $timezone && PHP_VERSION_ID < 70000) { + if (null === $timezone && \PHP_VERSION_ID < 70000) { // https://bugs.php.net/bug.php?id=68669 $object = \DateTime::class === $class ? \DateTime::createFromFormat($dateTimeFormat, $data) : \DateTimeImmutable::createFromFormat($dateTimeFormat, $data); } else { @@ -132,7 +133,7 @@ */ private function formatDateTimeErrors(array $errors) { - $formattedErrors = array(); + $formattedErrors = []; foreach ($errors as $pos => $message) { $formattedErrors[] = sprintf('at position %d: %s', $pos, $message);