You are here

public static function DateiCalParse::ical_date in Date 8

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 DateiCalParse::ical_date()
DateiCalParse::build_rrule in date_api/lib/Drupal/date_api/DateiCalParse.php
The reverse of the parse_rrule() function.
DateRRuleCalc::__construct in date_repeat/lib/Drupal/date_repeat/DateRRuleCalc.php
Compute dates that match the requested rule, within a specified date range.
date_repeat_build_dates in date_repeat_field/date_repeat_field.module
Helper function to build repeating dates from an $entity field.
date_repeat_rrule_description in date_repeat/date_repeat.module
Build a description of an iCal rule.

File

date_api/lib/Drupal/date_api/DateiCalParse.php, line 587
Parse iCal data.

Class

DateiCalParse
Return an array of iCalendar information from an iCalendar file.

Namespace

Drupal\date_api

Code

public static function ical_date($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 = drupal_get_user_timezone();
  }
  else {
    $from_tz = $ical_date['tz'];
  }
  if (strlen($ical_date['datetime']) < 11) {
    $ical_date['datetime'] .= ' 00:00:00';
  }
  $date = new DrupalDateTime($ical_date['datetime'], new \DateTimeZone($from_tz));
  if ($to_tz && $ical_date['tz'] != '' && $to_tz != $ical_date['tz']) {
    date_timezone_set($date, timezone_open($to_tz));
  }
  return $date;
}