ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\VObject\TimeZoneUtil Class Reference

Time zone name translation. More...

+ Collaboration diagram for Sabre\VObject\TimeZoneUtil:

Static Public Member Functions

static static getTimeZone ($tzid, Component $vcalendar=null, $failIfUncertain=false)
 This method will try to find out the correct timezone for an iCalendar date-time value. More...
 
static loadTzMaps ()
 This method will load in all the tz mapping information, if it's not yet done. More...
 
static getIdentifiersBC ()
 This method returns an array of timezone identifiers, that are supported by DateTimeZone(), but not returned by DateTimeZone::listIdentifiers(). More...
 

Static Public Attributes

static $map = null
 
static $microsoftExchangeMap
 List of microsoft exchange timezone ids. More...
 

Detailed Description

Time zone name translation.

This file translates well-known time zone names into "Olson database" time zone names.

Author
Frank Edelhaeuser (fedel.nosp@m.@use.nosp@m.rs.so.nosp@m.urce.nosp@m.forge.nosp@m..net)
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 15 of file TimeZoneUtil.php.

Member Function Documentation

◆ getIdentifiersBC()

static Sabre\VObject\TimeZoneUtil::getIdentifiersBC ( )
static

This method returns an array of timezone identifiers, that are supported by DateTimeZone(), but not returned by DateTimeZone::listIdentifiers().

We're not using DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC) because:

  • It's not supported by some PHP versions as well as HHVM.
  • It also returns identifiers, that are invalid values for new DateTimeZone() on some PHP versions. (See timezonedata/php-bc.php and timezonedata php-workaround.php)
Returns
array

Definition at line 272 of file TimeZoneUtil.php.

Referenced by Sabre\VObject\TimeZoneUtilTest\getPHPTimeZoneBCIdentifiers().

272  {
273  return include __DIR__ . '/timezonedata/php-bc.php';
274  }
+ Here is the caller graph for this function:

◆ getTimeZone()

static static Sabre\VObject\TimeZoneUtil::getTimeZone (   $tzid,
Component  $vcalendar = null,
  $failIfUncertain = false 
)
static

This method will try to find out the correct timezone for an iCalendar date-time value.

You must pass the contents of the TZID parameter, as well as the full calendar.

If the lookup fails, this method will return the default PHP timezone (as configured using date_default_timezone_set, or the date.timezone ini setting).

Alternatively, if $failIfUncertain is set to true, it will throw an exception if we cannot accurately determine the timezone.

Parameters
string$tzid
Sabre\VObject\Component$vcalendar
Returns
DateTimeZone

Definition at line 125 of file TimeZoneUtil.php.

References $map.

Referenced by Sabre\VObject\Property\ICalendar\DateTime\getDateTimes(), Sabre\VObject\Component\VTimeZone\getTimeZone(), Sabre\VObject\TimeZoneUtilTest\testExchangeMap(), Sabre\VObject\TimeZoneUtilTest\testFallBack(), Sabre\VObject\TimeZoneUtilTest\testLjubljanaBug(), Sabre\VObject\TimeZoneUtilTest\testPrefixedOffsetExchangeIdentifier(), Sabre\VObject\TimeZoneUtilTest\testTimeZoneBCIdentifiers(), Sabre\VObject\TimeZoneUtilTest\testTimezoneFail(), Sabre\VObject\TimeZoneUtilTest\testTimeZoneIdentifiers(), Sabre\VObject\TimeZoneUtilTest\testTimezoneOffset(), Sabre\VObject\TimeZoneUtilTest\testUnknownExchangeId(), Sabre\VObject\TimeZoneUtilTest\testWeirdSystemVLICs(), Sabre\VObject\TimeZoneUtilTest\testWetherMicrosoftIsStillInsane(), and Sabre\VObject\TimeZoneUtilTest\testWindowsTimeZone().

125  {
126 
127  // First we will just see if the tzid is a support timezone identifier.
128  //
129  // The only exception is if the timezone starts with (. This is to
130  // handle cases where certain microsoft products generate timezone
131  // identifiers that for instance look like:
132  //
133  // (GMT+01.00) Sarajevo/Warsaw/Zagreb
134  //
135  // Since PHP 5.5.10, the first bit will be used as the timezone and
136  // this method will return just GMT+01:00. This is wrong, because it
137  // doesn't take DST into account.
138  if ($tzid[0] !== '(') {
139 
140  // PHP has a bug that logs PHP warnings even it shouldn't:
141  // https://bugs.php.net/bug.php?id=67881
142  //
143  // That's why we're checking if we'll be able to successfull instantiate
144  // \DateTimeZone() before doing so. Otherwise we could simply instantiate
145  // and catch the exception.
146  $tzIdentifiers = \DateTimeZone::listIdentifiers();
147 
148  try {
149  if (
150  (in_array($tzid, $tzIdentifiers)) ||
151  (preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches)) ||
152  (in_array($tzid, self::getIdentifiersBC()))
153  ) {
154  return new \DateTimeZone($tzid);
155  }
156  } catch (\Exception $e) {
157  }
158 
159  }
160 
161  self::loadTzMaps();
162 
163  // Next, we check if the tzid is somewhere in our tzid map.
164  if (isset(self::$map[$tzid])) {
165  return new \DateTimeZone(self::$map[$tzid]);
166  }
167 
168  // Some Microsoft products prefix the offset first, so let's strip that off
169  // and see if it is our tzid map. We don't want to check for this first just
170  // in case there are overrides in our tzid map.
171  if (preg_match('/^\((UTC|GMT)(\+|\-)[\d]{2}\:[\d]{2}\) (.*)/', $tzid, $matches)) {
172  $tzidAlternate = $matches[3];
173  if (isset(self::$map[$tzidAlternate])) {
174  return new \DateTimeZone(self::$map[$tzidAlternate]);
175  }
176  }
177 
178  // Maybe the author was hyper-lazy and just included an offset. We
179  // support it, but we aren't happy about it.
180  if (preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches)) {
181 
182  // Note that the path in the source will never be taken from PHP 5.5.10
183  // onwards. PHP 5.5.10 supports the "GMT+0100" style of format, so it
184  // already gets returned early in this function. Once we drop support
185  // for versions under PHP 5.5.10, this bit can be taken out of the
186  // source.
187  // @codeCoverageIgnoreStart
188  return new \DateTimeZone('Etc/GMT' . $matches[1] . ltrim(substr($matches[2], 0, 2), '0'));
189  // @codeCoverageIgnoreEnd
190  }
191 
192  if ($vcalendar) {
193 
194  // If that didn't work, we will scan VTIMEZONE objects
195  foreach ($vcalendar->select('VTIMEZONE') as $vtimezone) {
196 
197  if ((string)$vtimezone->TZID === $tzid) {
198 
199  // Some clients add 'X-LIC-LOCATION' with the olson name.
200  if (isset($vtimezone->{'X-LIC-LOCATION'})) {
201 
202  $lic = (string)$vtimezone->{'X-LIC-LOCATION'};
203 
204  // Libical generators may specify strings like
205  // "SystemV/EST5EDT". For those we must remove the
206  // SystemV part.
207  if (substr($lic, 0, 8) === 'SystemV/') {
208  $lic = substr($lic, 8);
209  }
210 
211  return self::getTimeZone($lic, null, $failIfUncertain);
212 
213  }
214  // Microsoft may add a magic number, which we also have an
215  // answer for.
216  if (isset($vtimezone->{'X-MICROSOFT-CDO-TZID'})) {
217  $cdoId = (int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->getValue();
218 
219  // 2 can mean both Europe/Lisbon and Europe/Sarajevo.
220  if ($cdoId === 2 && strpos((string)$vtimezone->TZID, 'Sarajevo') !== false) {
221  return new \DateTimeZone('Europe/Sarajevo');
222  }
223 
224  if (isset(self::$microsoftExchangeMap[$cdoId])) {
225  return new \DateTimeZone(self::$microsoftExchangeMap[$cdoId]);
226  }
227  }
228 
229  }
230 
231  }
232 
233  }
234 
235  if ($failIfUncertain) {
236  throw new \InvalidArgumentException('We were unable to determine the correct PHP timezone for tzid: ' . $tzid);
237  }
238 
239  // If we got all the way here, we default to UTC.
240  return new \DateTimeZone(date_default_timezone_get());
241 
242  }
+ Here is the caller graph for this function:

◆ loadTzMaps()

static Sabre\VObject\TimeZoneUtil::loadTzMaps ( )
static

This method will load in all the tz mapping information, if it's not yet done.

Definition at line 248 of file TimeZoneUtil.php.

References $map.

Referenced by Sabre\VObject\TimeZoneUtilTest\getMapping().

248  {
249 
250  if (!is_null(self::$map)) return;
251 
252  self::$map = array_merge(
253  include __DIR__ . '/timezonedata/windowszones.php',
254  include __DIR__ . '/timezonedata/lotuszones.php',
255  include __DIR__ . '/timezonedata/exchangezones.php',
256  include __DIR__ . '/timezonedata/php-workaround.php'
257  );
258 
259  }
+ Here is the caller graph for this function:

Field Documentation

◆ $map

Sabre\VObject\TimeZoneUtil::$map = null
static

Definition at line 17 of file TimeZoneUtil.php.

Referenced by Sabre\VObject\TimeZoneUtilTest\getMapping().

◆ $microsoftExchangeMap

Sabre\VObject\TimeZoneUtil::$microsoftExchangeMap
static
Initial value:
= [
0 => 'UTC'

List of microsoft exchange timezone ids.

Source: http://msdn.microsoft.com/en-us/library/aa563018(loband).aspx

Definition at line 24 of file TimeZoneUtil.php.


The documentation for this class was generated from the following file: