diff --git a/src/Symfony/Component/Intl/Tests/TimezonesTest.php b/src/Symfony/Component/Intl/Tests/TimezonesTest.php index 025a9cbba52f0..f47af2105af12 100644 --- a/src/Symfony/Component/Intl/Tests/TimezonesTest.php +++ b/src/Symfony/Component/Intl/Tests/TimezonesTest.php @@ -663,4 +663,10 @@ public function provideCountries(): iterable return [$country]; }, Countries::getCountryCodes()); } + + public function testGetRawOffsetChangeTimeCountry() + { + $this->assertSame(7200, Timezones::getRawOffset('Europe/Paris', (new \DateTime('2022-07-16 00:00:00+00:00'))->getTimestamp())); + $this->assertSame(3600, Timezones::getRawOffset('Europe/Paris', (new \DateTime('2022-02-16 00:00:00+00:00'))->getTimestamp())); + } } diff --git a/src/Symfony/Component/Intl/Timezones.php b/src/Symfony/Component/Intl/Timezones.php index dd72d35925f40..265d0ede416cf 100644 --- a/src/Symfony/Component/Intl/Timezones.php +++ b/src/Symfony/Component/Intl/Timezones.php @@ -68,17 +68,9 @@ public static function getNames(string $displayLocale = null): array */ public static function getRawOffset(string $timezone, int $timestamp = null): int { - if (null === $timestamp) { - $timestamp = time(); - } - - $transitions = (new \DateTimeZone($timezone))->getTransitions($timestamp, $timestamp); - - if (!isset($transitions[0]['offset'])) { - throw new RuntimeException('No timezone transitions available.'); - } + $dateTimeImmutable = new \DateTimeImmutable(date('Y-m-d H:i:s', $timestamp ?? time()), new \DateTimeZone($timezone)); - return $transitions[0]['offset']; + return $dateTimeImmutable->getOffset(); } public static function getGmtOffset(string $timezone, int $timestamp = null, string $displayLocale = null): string