Skip to content

Commit 8477660

Browse files
committed
DateTime: refactoring
1 parent b89d891 commit 8477660

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/Utils/DateTime.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class DateTime extends \DateTime implements \JsonSerializable
4545
public static function from(string|int|\DateTimeInterface|null $time): static
4646
{
4747
if ($time instanceof \DateTimeInterface) {
48-
return new static($time->format('Y-m-d H:i:s.u'), $time->getTimezone());
48+
return static::createFromInterface($time);
4949

5050
} elseif (is_numeric($time)) {
5151
if ($time <= self::YEAR) {
@@ -96,10 +96,7 @@ public static function createFromFormat(
9696
string|\DateTimeZone|null $timezone = null,
9797
): static|false
9898
{
99-
if ($timezone === null) {
100-
$timezone = new \DateTimeZone(date_default_timezone_get());
101-
102-
} elseif (is_string($timezone)) {
99+
if (is_string($timezone)) {
103100
$timezone = new \DateTimeZone($timezone);
104101
}
105102

@@ -149,7 +146,7 @@ public function setTime(int $hour, int $minute, int $second = 0, int $microsecon
149146
*/
150147
public static function relativeToSeconds(string $relativeTime): int
151148
{
152-
return (new \DateTimeImmutable('1970-01-01 ' . $relativeTime, new \DateTimeZone('UTC')))
149+
return (new \DateTimeImmutable('@0 ' . $relativeTime))
153150
->getTimestamp();
154151
}
155152

0 commit comments

Comments
 (0)