You are here

protected function ParserVcalendar::_tzid_to_datetimezone in Date iCal 7.3

Internal helper function for creating DateTimeZone objects.

2 calls to ParserVcalendar::_tzid_to_datetimezone()
ParserVcalendar::parse in libraries/ParserVcalendar.inc
Parses the vcalendar object into an array of event data arrays.
ParserVcalendar::parseDateTimeProperty in libraries/ParserVcalendar.inc
Handler that parses DATE-TIME and DATE fields.

File

libraries/ParserVcalendar.inc, line 544
Defines a class that parses iCalcreator vcalendar objects into Feeds-compatible data arrays.

Class

ParserVcalendar
@file Defines a class that parses iCalcreator vcalendar objects into Feeds-compatible data arrays.

Code

protected function _tzid_to_datetimezone($tzid) {
  try {
    $datetimezone = new DateTimeZone($tzid);
  } catch (Exception $e) {

    // In case this is a Windows TZID, read the mapping file to try and
    // convert it to a real TZID.
    $zones = file_get_contents(drupal_get_path('module', 'date_ical') . '/libraries/windowsZones.json');
    $zones_assoc = json_decode($zones, TRUE);
    $windows_to_olson_map = array();
    foreach ($zones_assoc['supplemental']['windowsZones']['mapTimezones'] as $mapTimezone) {
      if ($mapTimezone['mapZone']['_other'] == $tzid) {

        // Parse out the space-separated TZIDs from $mapTimezone['mapZone']['_type'].
        $tzids = preg_split('/\\s/', $mapTimezone['mapZone']['_type']);
        try {

          // They all have the same UTC offset, so for our purposes we can
          // just take the first one.
          return new DateTimeZone($tzids[0]);
        } catch (Exception $e) {

          // If this one also fails, we're out of luck, so just fall through
          // to the regular error report code.
          break;
        }
      }
    }
    $tz_wiki = l(t('here'), 'http://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List');
    $help = l(t('README'), 'admin/help/date_ical', array(
      'absolute' => TRUE,
    ));
    $msg = t('"@tz" is not a valid timezone (see the TZ column !here), so Date iCal had to fall back to UTC (which is probably wrong!).<br>
          Please read the Date iCal !readme for instructions on how to fix this.', array(
      '@tz' => $tzid,
      '!here' => $tz_wiki,
      '!readme' => $help,
    ));
    $this->source
      ->log('parse', $msg, array(), WATCHDOG_WARNING);
    drupal_set_message($msg, 'warning', FALSE);
    $datetimezone = new DateTimeZone('UTC');
  }
  return $datetimezone;
}