Skip to content

Commit 9bea1cb

Browse files
Lenny4nicolas-grekas
authored andcommitted
[Intl] fix wrong offset timezone PHP 8.1
1 parent 98e367e commit 9bea1cb

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Tests/TimezonesTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,4 +663,10 @@ public function provideCountries(): iterable
663663
return [$country];
664664
}, Countries::getCountryCodes());
665665
}
666+
667+
public function testGetRawOffsetChangeTimeCountry()
668+
{
669+
$this->assertSame(7200, Timezones::getRawOffset('Europe/Paris', (new \DateTime('2022-07-16 00:00:00+00:00'))->getTimestamp()));
670+
$this->assertSame(3600, Timezones::getRawOffset('Europe/Paris', (new \DateTime('2022-02-16 00:00:00+00:00'))->getTimestamp()));
671+
}
666672
}

Timezones.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,9 @@ public static function getNames(string $displayLocale = null): array
6868
*/
6969
public static function getRawOffset(string $timezone, int $timestamp = null): int
7070
{
71-
if (null === $timestamp) {
72-
$timestamp = time();
73-
}
74-
75-
$transitions = (new \DateTimeZone($timezone))->getTransitions($timestamp, $timestamp);
76-
77-
if (!isset($transitions[0]['offset'])) {
78-
throw new RuntimeException('No timezone transitions available.');
79-
}
71+
$dateTimeImmutable = new \DateTimeImmutable(date('Y-m-d H:i:s', $timestamp ?? time()), new \DateTimeZone($timezone));
8072

81-
return $transitions[0]['offset'];
73+
return $dateTimeImmutable->getOffset();
8274
}
8375

8476
public static function getGmtOffset(string $timezone, int $timestamp = null, string $displayLocale = null): string

0 commit comments

Comments
 (0)