From e18f607b38c3195770da0e17b21550c750669248 Mon Sep 17 00:00:00 2001 From: Ren Xie Liu Date: Wed, 8 May 2024 16:41:59 +0800 Subject: [PATCH] Fix customized timezone guesser --- .../GuessFromCustomizedTimeZone.php | 5 ++- tests/VObject/TimeZoneUtilTest.php | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/TimezoneGuesser/GuessFromCustomizedTimeZone.php b/lib/TimezoneGuesser/GuessFromCustomizedTimeZone.php index 61d531cdf..f1f4f6899 100644 --- a/lib/TimezoneGuesser/GuessFromCustomizedTimeZone.php +++ b/lib/TimezoneGuesser/GuessFromCustomizedTimeZone.php @@ -45,11 +45,12 @@ public function guess(VTimeZone $vtimezone, ?bool $failIfUncertain = false): ?\D $daylightIterator = $daylight ? new RRuleIterator($daylightRRule, $standardIterator->current()) : null; $daylightIterator && $daylightIterator->next(); + $day = 24 * 60 * 60; foreach ($timezones as $timezone) { $tz = new \DateTimeZone($timezone); // check standard $timestamp = $standardIterator->current()->getTimestamp(); - $transitions = $tz->getTransitions($timestamp, $timestamp + 1); + $transitions = $tz->getTransitions($timestamp + $day, $timestamp + $day + 1); if (empty($transitions)) { continue; } @@ -66,7 +67,7 @@ public function guess(VTimeZone $vtimezone, ?bool $failIfUncertain = false): ?\D // check daylight $timestamp = $daylightIterator->current()->getTimestamp(); - $transitions = $tz->getTransitions($timestamp, $timestamp + 1); + $transitions = $tz->getTransitions($timestamp + $day, $timestamp + $day + 1); if (empty($transitions)) { continue; } diff --git a/tests/VObject/TimeZoneUtilTest.php b/tests/VObject/TimeZoneUtilTest.php index 1069b437a..fa71b17b4 100644 --- a/tests/VObject/TimeZoneUtilTest.php +++ b/tests/VObject/TimeZoneUtilTest.php @@ -671,6 +671,49 @@ public function testCustomizedTimeZone(): void self::assertSame(11 * 60 * 60, $tz->getOffset($start)); } + public function testCustomizedTimeZone2(): void + { + $ics = <<getName()); + $start = new \DateTimeImmutable('2022-04-25'); + self::assertSame(2 * 60 * 60, $tz->getOffset($start)); + + $start = new \DateTimeImmutable('2022-11-10'); + self::assertSame(60 * 60, $tz->getOffset($start)); + } + public function testCustomizedTimeZoneWithoutDaylight(): void { $ics = $this->getCustomizedICS();