public static function DateiCalParse::parse_duration in Date 8
Parses the duration of the event.
Example: DURATION:PT1H30M DURATION:P1Y2M
Parameters
array $subgroup: Array of other values in the vevent so we can check for DTSTART.
1 call to DateiCalParse::parse_duration()
- DateiCalParse::parse in date_api/
lib/ Drupal/ date_api/ DateiCalParse.php - Returns an array of iCalendar information from an iCalendar file.
File
- date_api/
lib/ Drupal/ date_api/ DateiCalParse.php, line 513 - Parse iCal data.
Class
- DateiCalParse
- Return an array of iCalendar information from an iCalendar file.
Namespace
Drupal\date_apiCode
public static function parse_duration(&$subgroup, $field = 'DURATION') {
$items = $subgroup[$field];
$data = $items['DATA'];
$interval = new \DateInterval($data);
$start_date = array_key_exists('DTSTART', $subgroup) ? $subgroup['DTSTART']['datetime'] : date_format(new DrupalDateTime(), DATE_FORMAT_ISO);
$timezone = array_key_exists('DTSTART', $subgroup) ? $subgroup['DTSTART']['tz'] : $this->timezone_name;
if (empty($timezone)) {
$timezone = 'UTC';
}
$date = new DrupalDateTime($start_date, $timezone);
$date2 = clone $date;
$date2
->add($interval);
$format = isset($subgroup['DTSTART']['type']) && $subgroup['DTSTART']['type'] == 'DATE' ? 'Y-m-d' : 'Y-m-d H:i:s';
$subgroup['DTEND'] = array(
'datetime' => date_format($date2, DATE_FORMAT_DATETIME),
'all_day' => isset($subgroup['DTSTART']['all_day']) ? $subgroup['DTSTART']['all_day'] : 0,
'tz' => $timezone,
);
$duration = date_format($date2, 'U') - date_format($date, 'U');
$subgroup['DURATION'] = array(
'DATA' => $data,
'DURATION' => $duration,
);
}