Use Horde_Date to do this parsing.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 9 Aug 2010 16:49:35 +0000 (12:49 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 9 Aug 2010 16:49:35 +0000 (12:49 -0400)
Be more friendly to dates that are past the maximum integer timestamp value.
Fixes an issue for me that was causing corrupted recurenddate values.

Jan, can you take a look and make sure this doesn't break anything else I might be
overlooking. All the .phpt tests are currently passing.

framework/Icalendar/lib/Horde/Icalendar.php

index 8ee462f..de2bc0a 100644 (file)
@@ -1282,31 +1282,20 @@ class Horde_Icalendar
      * @todo A bunch of code calls this function outside this class, so it
      * needs to be marked public for now.
      *
-     * @param $value TODO
+     * @param integer|object|array $value  The time value to export (either a
+     *                                     Horde_Date, array, or timestamp).
      *
-     * @return TODO
+     * @return string  The string representation of the datetime value.
      */
     public function _exportDateTime($value)
     {
-        $temp = array();
-        if (!is_object($value) && !is_array($value)) {
-            $tz = date('O', $value);
-            $TZOffset = (3600 * substr($tz, 0, 3)) + (60 * substr(date('O', $value), 3, 2));
-            $value -= $TZOffset;
-
-            $temp['zone']   = 'UTC';
-            $temp['year']   = date('Y', $value);
-            $temp['month']  = date('n', $value);
-            $temp['mday']   = date('j', $value);
-            $temp['hour']   = date('G', $value);
-            $temp['minute'] = date('i', $value);
-            $temp['second'] = date('s', $value);
-        } else {
-            $dateOb = new Horde_Date($value);
-            return $this->_exportDateTime($dateOb->timestamp());
-        }
-
-        return $this->_exportDate($temp) . 'T' . $this->_exportTime($temp);
+        $date = new Horde_Date($value);
+        $date->setTimezone('UTC');
+        $time = array('hour' => $date->hour,
+                      'minute' => $date->min,
+                      'second' => $date->sec,
+                      'zone' => 'UTC');
+        return $this->_exportDate($date) . 'T' . $this->_exportTime($time);
     }
 
     /**
@@ -1333,9 +1322,9 @@ class Horde_Icalendar
     /**
      * Exports a Time field.
      *
-     * @param $value TODO
+     * @param array $value An array of time parts.
      *
-     * @return TODO
+     * @return string  hhmmss[Z] representation of the time
      */
     protected function _exportTime($value)
     {