function date_ical_parse_date in Date 5
Same name and namespace in other branches
- 5.2 date_api_ical.inc \date_ical_parse_date()
- 6.2 date_api_ical.inc \date_ical_parse_date()
- 6 date_api_ical.inc \date_ical_parse_date()
- 7.3 date_api/date_api_ical.inc \date_ical_parse_date()
- 7 date_api/date_api_ical.inc \date_ical_parse_date()
- 7.2 date_api/date_api_ical.inc \date_ical_parse_date()
Parse a ical date element.
Possible formats to parse include: PROPERTY:YYYYMMDD[T][HH][MM][SS][Z] PROPERTY;VALUE=DATE:YYYYMMDD[T][HH][MM][SS][Z] PROPERTY;VALUE=DATE-TIME:YYYYMMDD[T][HH][MM][SS][Z] PROPERTY;TZID=XXXXXXXX;VALUE=DATE:YYYYMMDD[T][HH][MM][SS] PROPERTY;TZID=XXXXXXXX:YYYYMMDD[T][HH][MM][SS]
The property and the colon before the date are removed in the import process above and we are left with $field and $data.
Parameters
$field: The text before the colon and the date, i.e. ';VALUE=DATE:', ';VALUE=DATE-TIME:', ';TZID=' @param $data The date itself, after the colon, in the format YYYYMMDD[T][HH][MM][SS][Z] 'Z', if supplied, means the date is in UTC.
@return array $items array, consisting of: 'datetime' => date in YYYY-MM-DD HH:MM format, not timezone adjusted 'all_day' => whether this is an all-day event with no time 'tz' => the timezone of the date, could be blank if the ical has no timezone; the ical specs say no timezone conversion should be done if no timezone info is supplied @todo Another option for dates is the format PROPERTY;VALUE=PERIOD:XXXX. The period may include a duration, or a date and a duration, or two dates, so would have to be split into parts and run through date_ical_parse_date() and date_ical_parse_duration(). This is not commonly used, so ignored for now. It will take more work to figure how to support that.
3 calls to date_ical_parse_date()
- date_ical_import in ./
date_api_ical.inc - Return an array of iCalendar information from an iCalendar file.
- date_ical_parse_exceptions in ./
date_api_ical.inc - Parse exception dates (can be multiple values).
- date_ical_parse_rule in ./
date_api_ical.inc - Parse an ical repeat rule.
File
- ./
date_api_ical.inc, line 367 - Parse iCal imports and create iCal exports. This file must be included when these functions are needed.
Code
function date_ical_parse_date($field, $data) {
$tz = '';
$data = trim($data);
$items = array(
'DATA' => $data,
);
if (substr($data, -1) == 'Z') {
$tz = 'UTC';
}
if (strstr($field, 'TZID=')) {
$tmp = explode('=', $field);
// Fix commonly used alternatives like US-Eastern which should be US/Eastern.
$tz = str_replace('-', '/', $tmp[1]);
}
$data = str_replace(array(
'T',
'Z',
), '', $data);
preg_match(DATE_REGEX_LOOSE, $data, $regs);
if (!empty($regs[5])) {
$time = ' ' . date_pad($regs[5]) . ':' . date_pad($regs[6]) . ':' . date_pad($regs[7]);
}
$items['datetime'] = $regs[1] . '-' . $regs[2] . '-' . $regs[3] . $time;
$items['all_day'] = empty($time) ? 1 : 0;
$items['tz'] = $tz;
$items['granularity'] = empty($time) ? array(
'Y',
'M',
'D',
) : array(
'Y',
'M',
'D',
'H',
'N',
'S',
);
return $items;
}