-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow easier extension of the timezone guessing
This will ease customization of timezone-guessing as it is now gets easier to extend that process with own implementations (as long as they implement the appropriate interface) This is espechially necessary when wanting to actually guess a timezone via the rules defined in the VTIMEZONE-entry (which is currently not done)
- Loading branch information
1 parent
a7460c5
commit 87c8def
Showing
9 changed files
with
496 additions
and
132 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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sabre\VObject\TimezoneGuesser; | ||
|
||
use DateTimeZone; | ||
|
||
/** | ||
* Some clients add 'X-LIC-LOCATION' with the olson name. | ||
*/ | ||
class FindFromOffset implements TimezoneFinder | ||
{ | ||
public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone | ||
{ | ||
// Maybe the author was hyper-lazy and just included an offset. We | ||
// support it, but we aren't happy about it. | ||
if (preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches)) { | ||
// Note that the path in the source will never be taken from PHP 5.5.10 | ||
// onwards. PHP 5.5.10 supports the "GMT+0100" style of format, so it | ||
// already gets returned early in this function. Once we drop support | ||
// for versions under PHP 5.5.10, this bit can be taken out of the | ||
// source. | ||
// @codeCoverageIgnoreStart | ||
return new DateTimeZone('Etc/GMT'.$matches[1].ltrim(substr($matches[2], 0, 2), '0')); | ||
// @codeCoverageIgnoreEnd | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.