forked from sabre-io/vobject
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Calendar] Add FindFromOutlookCities timezone finder
- Loading branch information
Ren Xie Liu
committed
Apr 25, 2022
1 parent
5e4d88d
commit a0f5429
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sabre\VObject\TimezoneGuesser; | ||
|
||
use DateTimeZone; | ||
|
||
class FindFromOutlookCities implements TimezoneFinder | ||
{ | ||
/** | ||
* Example: TZID:(UTC+01:00) Bruxelles\, København\, Madrid\, Paris | ||
*/ | ||
public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone | ||
{ | ||
$values = explode(' ', $tzid); | ||
if (count($values) === 1) { | ||
return null; | ||
} | ||
|
||
unset($values[0]); | ||
$cities = implode('', $values); | ||
$cities = explode('\,', $cities); | ||
|
||
if (count($cities) === 1) { | ||
return null; | ||
} | ||
|
||
$tzIdentifiers = DateTimeZone::listIdentifiers(); | ||
|
||
foreach ($cities as $city) { | ||
foreach ($tzIdentifiers as $tzIdentifier) { | ||
if (str_contains(strtolower($tzIdentifier), strtolower($city))) { | ||
return new DateTimeZone($tzIdentifier); | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters