GuessFromLicEntry.php 846 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\VObject\TimezoneGuesser;
  4. use DateTimeZone;
  5. use Sabre\VObject\Component\VTimeZone;
  6. use Sabre\VObject\TimeZoneUtil;
  7. /**
  8. * Some clients add 'X-LIC-LOCATION' with the olson name.
  9. */
  10. class GuessFromLicEntry implements TimezoneGuesser
  11. {
  12. public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?DateTimeZone
  13. {
  14. if (!isset($vtimezone->{'X-LIC-LOCATION'})) {
  15. return null;
  16. }
  17. $lic = (string) $vtimezone->{'X-LIC-LOCATION'};
  18. // Libical generators may specify strings like
  19. // "SystemV/EST5EDT". For those we must remove the
  20. // SystemV part.
  21. if ('SystemV/' === substr($lic, 0, 8)) {
  22. $lic = substr($lic, 8);
  23. }
  24. return TimeZoneUtil::getTimeZone($lic, null, $failIfUncertain);
  25. }
  26. }