You are here

public function ParserIcalCreator::formatDateTime in iCal feed parser 7.2

Format date fields.

Return value

FeedsDateTime

File

includes/ParserIcalCreator.inc, line 165
Basic classes.

Class

ParserIcalCreator
@file Basic classes.

Code

public function formatDateTime($property_key, $property, ParserIcalComponentInterface $item, ParserIcalResult $result, FeedsSource $source) {
  $d = $property['value'];
  if (isset($property['params']['VALUE']) && $property['params']['VALUE'] == 'DATE') {

    /**
     * DATE are 'anniversary type' day events, no time set.
     * This can span over multiple days.
     * FeedsDateTime sets the granularity correctly.
     * However the granularity is not used yet.
     * All Day events handling is not finalized at the time of writing.
     * Multiple day all day events are not handled at this point.
     * http://drupal.org/node/874322 To Date & All Day Date Handling
     */
    if ($property_key == 'dtend') {
      $s = $item
        ->getProperty('dtstart');
      $s = $s['value'];
      if ($s['year'] == $d['year'] && $s['month'] == $d['month'] && $s['day'] == $d['day'] - 1) {

        // Single day, all day event.
        // iCal DATE has start on day, end on next day.
        // Presently handled date.module by having same start and end dates.
        // See notes about timezone handling in issue above however.
        $d = $s;
      }
    }

    // order matters here dtstart has to come before dtend
    if ($property_key == 'dtstart') {
      if ($duration = $item
        ->getProperty('duration')) {

        // @todo there is handling in the iCalcreator Utils
      }
      elseif (!$item
        ->getProperty('dtend')) {

        // For cases where a "VEVENT"+... calendar component
        // specifies a "DTSTART" property with a DATE value type but no
        // "DTEND" nor "DURATION" property, the event's duration is taken to
        // be one day.
        $item
          ->setProperty('dtend', $property);
      }
    }
    $feeds_object = new FeedsDateTime($d['year'] . '-' . $d['month'] . '-' . $d['day']);
  }
  else {

    // Date with time.
    $date_string = iCalUtilityFunctions::_format_date_time($d);

    // If there was no timezone on the date string itself,
    // add one if we have one.
    if (empty($d['tz'])) {
      if (!empty($property['params']['TZID'])) {

        // timezone on the iCal DATETIME
        try {
          $tz = new DateTimeZone($property['params']['TZID']);

          // note: these should relate to the ParserIcalResult::$timezones
          // but see comment on property
        } catch (Exception $e) {
          $source
            ->log('parse', 'DATE-TIME TZID not in PHP timezonedb: %error', array(
            '%error' => $e
              ->getMessage(),
          ), WATCHDOG_NOTICE);
        }
      }
      elseif (!empty($result->timezone)) {

        // feed wide timezone
        $tz = $result->timezone;
      }
    }
    if (!(isset($tz) && is_a($tz, 'DateTimeZone'))) {
      $tz = NULL;
    }
    $feeds_object = new FeedsDateTime($date_string, $tz);
  }
  return $feeds_object;
}