FindFromOffset.php 1.0 KB

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