Skip to content

Commit

Permalink
fix!: now Time::createFromTimestamp() returns Time with UTC by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Aug 6, 2024
1 parent bc61694 commit 410635c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion system/I18n/TimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static function createFromTimestamp(int $timestamp, $timezone = null, ?st
{
$time = new self(gmdate('Y-m-d H:i:s', $timestamp), 'UTC', $locale);

$timezone ??= date_default_timezone_get();
$timezone ??= 'UTC';

return $time->setTimezone($timezone);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/system/I18n/TimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ public function testCreateFromTimestamp(): void

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

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

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

// Restore timezone.
date_default_timezone_set($tz);
Expand Down

0 comments on commit 410635c

Please sign in to comment.