diff --git a/lib/TimeZoneUtil.php b/lib/TimeZoneUtil.php index ec4a238d..b5d67998 100644 --- a/lib/TimeZoneUtil.php +++ b/lib/TimeZoneUtil.php @@ -4,6 +4,7 @@ use DateTimeZone; use InvalidArgumentException; +use Sabre\VObject\TimezoneGuesser\FindFromMzVersionTimezone; use Sabre\VObject\TimezoneGuesser\FindFromOffset; use Sabre\VObject\TimezoneGuesser\FindFromOutlookCities; use Sabre\VObject\TimezoneGuesser\FindFromTimezoneIdentifier; @@ -44,6 +45,7 @@ private function __construct() $this->addFinder('offset', new FindFromOffset()); $this->addFinder('lowercase', new LowercaseTimezoneIdentifier()); $this->addFinder('outlookCities', new FindFromOutlookCities()); + $this->addFinder('version', new FindFromMzVersionTimezone()); } private static function getInstance(): self diff --git a/lib/TimezoneGuesser/FindFromMzVersionTimezone.php b/lib/TimezoneGuesser/FindFromMzVersionTimezone.php new file mode 100644 index 00000000..d555084f --- /dev/null +++ b/lib/TimezoneGuesser/FindFromMzVersionTimezone.php @@ -0,0 +1,35 @@ + Eastern Standard Time + */ +class FindFromMzVersionTimezone implements TimezoneFinder +{ + public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone + { + if (strlen($tzid) < 1) { + return null; + } + + $trailingChar = (int) $tzid[strlen($tzid)-1]; + if ($trailingChar <= 9 && $trailingChar >= 1) { + $tz = TimeZoneUtil::getTimeZone(substr($tzid, 0, strrpos($tzid, ' '))); + if ($tz->getName() === 'UTC') { + return null; + } + + return $tz; + } + + return null; + } +} diff --git a/tests/VObject/TimeZoneUtilTest.php b/tests/VObject/TimeZoneUtilTest.php index f024b63b..eae789c5 100644 --- a/tests/VObject/TimeZoneUtilTest.php +++ b/tests/VObject/TimeZoneUtilTest.php @@ -533,4 +533,29 @@ public function outlookCitiesProvider(): iterable 'expected' => 'UTC', ]; } + + /** + * @dataProvider versionTzProvider + */ + public function testVersionTz(string $origin, bool $failIfUncertain, string $expected) + { + $tz = TimeZoneUtil::getTimeZone($origin, null, $failIfUncertain); + $ex = new \DateTimeZone($expected); + $this->assertEquals($ex->getName(), $tz->getName()); + } + + public function versionTzProvider(): iterable + { + yield 'case 1' => [ + 'origin' => 'Eastern Standard Time 1', + 'failIfUncertain' => true, + 'expected' => 'America/New_York', + ]; + + yield 'case 2' => [ + 'origin' => 'Eastern Standard Time 2', + 'failIfUncertain' => true, + 'expected' => 'America/New_York', + ]; + } }