Skip to content

Commit 2bd2545

Browse files
IBX-801: Fixed timezone for DateTime fields in content name pattern #4
1 parent bfb1140 commit 2bd2545

File tree

1 file changed

+5
-18
lines changed
  • eZ/Publish/Core/FieldType/DateAndTime

1 file changed

+5
-18
lines changed

eZ/Publish/Core/FieldType/DateAndTime/Value.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue;
1111
use Exception;
1212
use DateTime;
13-
use DateTimeZone;
1413

1514
/**
1615
* Value for DateAndTime field type.
@@ -51,7 +50,7 @@ public function __construct(DateTime $dateTime = null)
5150
public static function fromString($dateString)
5251
{
5352
try {
54-
return new static(static::getDateTime($dateString));
53+
return new static(new DateTime($dateString));
5554
} catch (Exception $e) {
5655
throw new InvalidArgumentValue('$dateString', $dateString, __CLASS__, $e);
5756
}
@@ -67,27 +66,15 @@ public static function fromString($dateString)
6766
public static function fromTimestamp($timestamp)
6867
{
6968
try {
70-
return new static(static::getDateTime("@{$timestamp}"));
69+
$dateTime = new DateTime();
70+
$dateTime->setTimestamp($timestamp);
71+
72+
return new static($dateTime);
7173
} catch (Exception $e) {
7274
throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e);
7375
}
7476
}
7577

76-
/**
77-
* Creates a DateTime object from the string with respecting server timezone.
78-
*
79-
* @param string $datetime
80-
*
81-
* @return \DateTime
82-
*/
83-
public static function getDateTime($datetime)
84-
{
85-
$dt = new DateTime($datetime);
86-
$dt->setTimezone(new DateTimeZone(date_default_timezone_get()));
87-
88-
return $dt;
89-
}
90-
9178
/**
9279
* @see \eZ\Publish\Core\FieldType\Value
9380
*/

0 commit comments

Comments
 (0)