From 2bd25455dac39eea7c6f93adc3c86f6764b7bf48 Mon Sep 17 00:00:00 2001 From: Serhey Dolgushev Date: Wed, 21 Jul 2021 14:51:22 +0100 Subject: [PATCH] IBX-801: Fixed timezone for DateTime fields in content name pattern #4 --- .../Core/FieldType/DateAndTime/Value.php | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/eZ/Publish/Core/FieldType/DateAndTime/Value.php b/eZ/Publish/Core/FieldType/DateAndTime/Value.php index 57b88bd0b9..702f8e9941 100644 --- a/eZ/Publish/Core/FieldType/DateAndTime/Value.php +++ b/eZ/Publish/Core/FieldType/DateAndTime/Value.php @@ -10,7 +10,6 @@ use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue; use Exception; use DateTime; -use DateTimeZone; /** * Value for DateAndTime field type. @@ -51,7 +50,7 @@ public function __construct(DateTime $dateTime = null) public static function fromString($dateString) { try { - return new static(static::getDateTime($dateString)); + return new static(new DateTime($dateString)); } catch (Exception $e) { throw new InvalidArgumentValue('$dateString', $dateString, __CLASS__, $e); } @@ -67,27 +66,15 @@ public static function fromString($dateString) public static function fromTimestamp($timestamp) { try { - return new static(static::getDateTime("@{$timestamp}")); + $dateTime = new DateTime(); + $dateTime->setTimestamp($timestamp); + + return new static($dateTime); } catch (Exception $e) { throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e); } } - /** - * Creates a DateTime object from the string with respecting server timezone. - * - * @param string $datetime - * - * @return \DateTime - */ - public static function getDateTime($datetime) - { - $dt = new DateTime($datetime); - $dt->setTimezone(new DateTimeZone(date_default_timezone_get())); - - return $dt; - } - /** * @see \eZ\Publish\Core\FieldType\Value */