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
663
663
return [$ country ];
664
664
}, Countries::getCountryCodes ());
665
665
}
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
+ }
666
672
}
Original file line number Diff line number Diff line change @@ -68,17 +68,9 @@ public static function getNames(string $displayLocale = null): array
68
68
*/
69
69
public static function getRawOffset (string $ timezone , int $ timestamp = null ): int
70
70
{
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 ));
80
72
81
- return $ transitions [ 0 ][ ' offset ' ] ;
73
+ return $ dateTimeImmutable -> getOffset () ;
82
74
}
83
75
84
76
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