function _parser_common_syndication_parse_w3cdtf in Feeds Atom 6
Same name and namespace in other branches
- 7 libraries/atomrdf_parser.inc \_parser_common_syndication_parse_w3cdtf()
Parse the W3C date/time format, a subset of ISO 8601.
PHP date parsing functions do not handle this format. See http://www.w3.org/TR/NOTE-datetime for more information. Originally from MagpieRSS (http://magpierss.sourceforge.net/).
Parameters
$date_str: A string with a potentially W3C DTF date.
Return value
A timestamp if parsed successfully or FALSE if not.
1 call to _parser_common_syndication_parse_w3cdtf()
- _parser_common_syndication_parse_date in libraries/
atomrdf_parser.inc - Parse a date comes from a feed.
File
- libraries/
atomrdf_parser.inc, line 454 - Contains the atomrd parsing functions.
Code
function _parser_common_syndication_parse_w3cdtf($date_str) {
if (preg_match('/(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2})(:(\\d{2}))?(?:([-+])(\\d{2}):?(\\d{2})|(Z))?/', $date_str, $match)) {
list($year, $month, $day, $hours, $minutes, $seconds) = array(
$match[1],
$match[2],
$match[3],
$match[4],
$match[5],
$match[6],
);
// Calculate the epoch for current date assuming GMT.
$epoch = gmmktime($hours, $minutes, $seconds, $month, $day, $year);
if ($match[10] != 'Z') {
// Z is zulu time, aka GMT
list($tz_mod, $tz_hour, $tz_min) = array(
$match[8],
$match[9],
$match[10],
);
// Zero out the variables.
if (!$tz_hour) {
$tz_hour = 0;
}
if (!$tz_min) {
$tz_min = 0;
}
$offset_secs = ($tz_hour * 60 + $tz_min) * 60;
// Is timezone ahead of GMT? If yes, subtract offset.
if ($tz_mod == '+') {
$offset_secs *= -1;
}
$epoch += $offset_secs;
}
return $epoch;
}
else {
return FALSE;
}
}