Skip to content

Commit 31a41d5

Browse files
authored
Merge pull request #4668 from MGatner/time-utc
UTC Time from timestamp
2 parents 2e0aa7b + 1c70ca6 commit 31a41d5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

system/I18n/Time.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public static function createFromFormat($format, $datetime, $timeZone = null)
297297
*/
298298
public static function createFromTimestamp(int $timestamp, $timezone = null, string $locale = null)
299299
{
300-
return new Time(date('Y-m-d H:i:s', $timestamp), $timezone, $locale);
300+
return new Time(gmdate('Y-m-d H:i:s', $timestamp), $timezone ?? 'UTC', $locale);
301301
}
302302

303303
//--------------------------------------------------------------------

tests/system/I18n/TimeTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,15 @@ public function testCreateFromFormatWithInvalidFormat()
212212

213213
public function testCreateFromTimestamp()
214214
{
215-
$time = Time::createFromTimestamp(strtotime('2017-03-18 midnight'));
215+
// Se the timezone temporarily to UTC to make sure the test timestamp is correct
216+
$tz = date_default_timezone_get();
217+
date_default_timezone_set('UTC');
218+
219+
$timestamp = strtotime('2017-03-18 midnight');
220+
221+
date_default_timezone_set($tz);
222+
223+
$time = Time::createFromTimestamp($timestamp);
216224

217225
$this->assertEquals(date('2017-03-18 00:00:00'), $time->toDateTimeString());
218226
}

0 commit comments

Comments
 (0)