[wp-cvs] wordpress/wp-includes functions-formatting.php,1.31,1.32

Michel Valdrighi michelvaldrighi at users.sourceforge.net
Mon May 31 12:02:12 CDT 2004


Update of /cvsroot/cafelog/wordpress/wp-includes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9051/wp-includes

Modified Files:
	functions-formatting.php 
Log Message:
added iso8601 handling functions, to avoid ugly nasty conversions

Index: functions-formatting.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/functions-formatting.php,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** functions-formatting.php	25 May 2004 04:33:37 -0000	1.31
--- functions-formatting.php	31 May 2004 17:02:09 -0000	1.32
***************
*** 415,417 ****
--- 415,448 ----
  }
  
+ // computes an offset in seconds from an iso8601 timezone
+ function iso8601_timezone_to_offset($timezone) {
+   // $timezone is either 'Z' or '[+|-]hhmm'
+   if ($timezone == 'Z') {
+     $offset = 0;
+   } else {
+     $sign    = (substr($timezone, 0, 1) == '+') ? 1 : -1;
+     $hours   = intval(substr($timezone, 1, 2));
+     $minutes = intval(substr($timezone, 3, 4)) / 60;
+     $offset  = $sign * 3600 * ($hours + $minutes);
+   }
+   return $offset;
+ }
+ 
+ // converts an iso8601 date to MySQL DateTime format used by post_date[_gmt]
+ function iso8601_to_datetime($date_string, $timezone = USER) {
+   if ($timezone == GMT) {
+     preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits);
+     if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset
+       $offset = iso8601_timezone_to_offset($date_bits[7]);
+     } else { // we don't have a timezone, so we assume user local timezone (not server's!)
+       $offset = 3600 * get_settings('gmt_offset');
+     }
+     $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
+     $timestamp -= $offset;
+     return gmdate('Y-m-d H:i:s', $timestamp);
+   } elseif ($timezone == USER) {
+     return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string);
+   }
+ }
+ 
  ?>
\ No newline at end of file




More information about the cvs mailing list