function aggregator_parse_w3cdtf

7.x aggregator.parser.inc aggregator_parse_w3cdtf($date_str)
6.x aggregator.module aggregator_parse_w3cdtf($date_str)

Parses 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 aggregator_parse_w3cdtf()
aggregator_parse_feed in drupal-7.x/modules/aggregator/aggregator.parser.inc
Parses a feed and stores its items.

File

drupal-7.x/modules/aggregator/aggregator.parser.inc, line 303
Parser functions for the aggregator module.

Code

function aggregator_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;
  }
}