forked from sabre-io/vobject
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Calendar] Handle version timezone (#58)
Co-authored-by: Ren Xie Liu <ren.xie@proton.ch>
- Loading branch information
Showing
3 changed files
with
62 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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sabre\VObject\TimezoneGuesser; | ||
|
||
use DateTimeZone; | ||
use Sabre\VObject\TimeZoneUtil; | ||
|
||
/** | ||
* Try to ignore the trailing number of the Microsoft timezone. | ||
* | ||
* For example: Eastern Standard Time 1 => 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; | ||
} | ||
} |
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