File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments