FindFromOffset.php
1 year ago
FindFromTimezoneIdentifier.php
1 year ago
FindFromTimezoneMap.php
1 year ago
GuessFromLicEntry.php
1 year ago
GuessFromMsTzId.php
1 year ago
TimezoneFinder.php
1 year ago
TimezoneGuesser.php
1 year ago
FindFromOffset.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Sabre\VObject\TimezoneGuesser; |
| 6 | |
| 7 | use DateTimeZone; |
| 8 | |
| 9 | /** |
| 10 | * Some clients add 'X-LIC-LOCATION' with the olson name. |
| 11 | */ |
| 12 | class FindFromOffset implements TimezoneFinder |
| 13 | { |
| 14 | public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone |
| 15 | { |
| 16 | // Maybe the author was hyper-lazy and just included an offset. We |
| 17 | // support it, but we aren't happy about it. |
| 18 | if (preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches)) { |
| 19 | // Note that the path in the source will never be taken from PHP 5.5.10 |
| 20 | // onwards. PHP 5.5.10 supports the "GMT+0100" style of format, so it |
| 21 | // already gets returned early in this function. Once we drop support |
| 22 | // for versions under PHP 5.5.10, this bit can be taken out of the |
| 23 | // source. |
| 24 | // @codeCoverageIgnoreStart |
| 25 | return new DateTimeZone('Etc/GMT'.$matches[1].ltrim(substr($matches[2], 0, 2), '0')); |
| 26 | // @codeCoverageIgnoreEnd |
| 27 | } |
| 28 | |
| 29 | return null; |
| 30 | } |
| 31 | } |
| 32 |