You are here

function date_ical_date in Date 7.2

Same name and namespace in other branches
  1. 5.2 date_api_ical.inc \date_ical_date()
  2. 5 date_api_ical.inc \date_ical_date()
  3. 6.2 date_api_ical.inc \date_ical_date()
  4. 6 date_api_ical.inc \date_ical_date()
  5. 7.3 date_api/date_api_ical.inc \date_ical_date()
  6. 7 date_api/date_api_ical.inc \date_ical_date()

Return a date object for the ical date, adjusted to its local timezone.

Parameters

array $ical_date: An array of ical date information created in the ical import.

string $to_tz: The timezone to convert the date's value to.

Return value

object A timezone-adjusted date object.

4 calls to date_ical_date()
date_api_ical_build_rrule in date_api/date_api_ical.inc
Build an iCal RULE from $form_values.
date_repeat_build_dates in date_repeat_field/date_repeat_field.module
Helper function to build repeating dates from a $node_field.
date_repeat_rrule_description in date_repeat/date_repeat.module
Build a description of an iCal rule.
_date_repeat_calc in date_repeat/date_repeat_calc.inc
Private implementation of date_repeat_calc().

File

date_api/date_api_ical.inc, line 607
Parse iCal data.

Code

function date_ical_date(array $ical_date, $to_tz = FALSE) {

  // If the ical date has no timezone, must assume it is stateless
  // so treat it as a local date.
  if (empty($ical_date['datetime'])) {
    return NULL;
  }
  elseif (empty($ical_date['tz'])) {
    $from_tz = date_default_timezone();
  }
  else {
    $from_tz = $ical_date['tz'];
  }
  if (strlen($ical_date['datetime']) < 11) {
    $ical_date['datetime'] .= ' 00:00:00';
  }
  $date = new DateObject($ical_date['datetime'], new DateTimeZone($from_tz));
  if ($to_tz && !empty($ical_date['tz']) && $to_tz != $ical_date['tz']) {
    date_timezone_set($date, timezone_open($to_tz));
  }
  return $date;
}