Skip to content

Commit ba0db95

Browse files
committed
DateTime: refactoring
1 parent e8f4560 commit ba0db95

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
@@ -10,7 +10,7 @@
1010
namespace Nette\Utils;
1111

1212
use Nette;
13-
use function array_merge, checkdate, date_default_timezone_get, implode, is_numeric, is_string, preg_replace_callback, sprintf, time, trim;
13+
use function array_merge, checkdate, implode, is_numeric, is_string, preg_replace_callback, sprintf, time, trim;
1414

1515

1616
/**
@@ -46,7 +46,7 @@ class DateTime extends \DateTime implements \JsonSerializable
4646
public static function from(string|int|\DateTimeInterface|null $time): static
4747
{
4848
if ($time instanceof \DateTimeInterface) {
49-
return new static($time->format('Y-m-d H:i:s.u'), $time->getTimezone());
49+
return static::createFromInterface($time);
5050

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

0 commit comments

Comments
 (0)