parse_w3cdtf

The WordPress Core parse w3cdtf function.

Description

parse_w3cdtf( $date_str ); 

Parameters (1)

0. $date_str
The date str.

Usage

  1. if ( !function_exists( 'parse_w3cdtf' ) ) { 
  2. require_once ABSPATH . WPINC . '/rss.php'; 
  3.  
  4. // The date str. 
  5. $date_str = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = parse_w3cdtf($date_str); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/rss.php  
  1. function parse_w3cdtf ( $date_str ) { 
  2.  
  3. # regex to match wc3dtf 
  4. $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; 
  5.  
  6. if ( preg_match( $pat, $date_str, $match ) ) { 
  7. list( $year, $month, $day, $hours, $minutes, $seconds) = 
  8. array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[7]); 
  9.  
  10. # calc epoch for current date assuming GMT 
  11. $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); 
  12.  
  13. $offset = 0; 
  14. if ( $match[11] == 'Z' ) { 
  15. # zulu time, aka GMT 
  16. else { 
  17. list( $tz_mod, $tz_hour, $tz_min ) = 
  18. array( $match[8], $match[9], $match[10]); 
  19.  
  20. # zero out the variables 
  21. if ( ! $tz_hour ) { $tz_hour = 0; } 
  22. if ( ! $tz_min ) { $tz_min = 0; } 
  23.  
  24. $offset_secs = (($tz_hour*60)+$tz_min)*60; 
  25.  
  26. # is timezone ahead of GMT? then subtract offset 
  27. if ( $tz_mod == '+' ) { 
  28. $offset_secs = $offset_secs * -1; 
  29.  
  30. $offset = $offset_secs; 
  31. $epoch = $epoch + $offset; 
  32. return $epoch; 
  33. else { 
  34. return -1;