Skip to content

Commit 410635c

Browse files
committed
fix!: now Time::createFromTimestamp() returns Time with UTC by default
1 parent bc61694 commit 410635c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

system/I18n/TimeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public static function createFromTimestamp(int $timestamp, $timezone = null, ?st
269269
{
270270
$time = new self(gmdate('Y-m-d H:i:s', $timestamp), 'UTC', $locale);
271271

272-
$timezone ??= date_default_timezone_get();
272+
$timezone ??= 'UTC';
273273

274274
return $time->setTimezone($timezone);
275275
}

tests/system/I18n/TimeTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,11 @@ public function testCreateFromTimestamp(): void
277277

278278
$timestamp = strtotime('2017-03-18 midnight');
279279

280+
// The timezone will be UTC if you don't specify.
280281
$time = Time::createFromTimestamp($timestamp);
281282

282-
$this->assertSame('Asia/Tokyo', $time->getTimezone()->getName());
283-
$this->assertSame('2017-03-18 00:00:00', $time->format('Y-m-d H:i:s'));
283+
$this->assertSame('UTC', $time->getTimezone()->getName());
284+
$this->assertSame('2017-03-17 15:00:00', $time->format('Y-m-d H:i:s'));
284285

285286
// Restore timezone.
286287
date_default_timezone_set($tz);

0 commit comments

Comments
 (0)