[Svn] r4439 - trunk/roundcubemail/program/include

trac at roundcube.net trac at roundcube.net
Fri Jan 21 17:50:07 CET 2011


Author: thomasb
Date: 2011-01-21 10:50:07 -0600 (Fri, 21 Jan 2011)
New Revision: 4439

Modified:
   trunk/roundcubemail/program/include/main.inc
   trunk/roundcubemail/program/include/rcube_imap_generic.php
Log:
Use improved strtotime() function + reduce duplicated code

Modified: trunk/roundcubemail/program/include/main.inc
===================================================================
--- trunk/roundcubemail/program/include/main.inc	2011-01-21 11:46:49 UTC (rev 4438)
+++ trunk/roundcubemail/program/include/main.inc	2011-01-21 16:50:07 UTC (rev 4439)
@@ -978,6 +978,37 @@
 
 
 /**
+ * Improved equivalent to strtotime()
+ *
+ * @param string Date string
+ * @return int 
+ */
+function rcube_strtotime($date)
+{
+  // check for MS Outlook vCard date format YYYYMMDD
+  if (preg_match('/^([12][90]\d\d)([01]\d)(\d\d)$/', trim($date), $matches)) {
+    return mktime(0,0,0, intval($matches[2]), intval($matches[3]), intval($matches[1]));
+  }
+  else if (is_numeric($date))
+    return $date;
+
+  // support non-standard "GMTXXXX" literal
+  $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date);
+
+  // if date parsing fails, we have a date in non-rfc format.
+  // remove token from the end and try again
+  while ((($ts = @strtotime($date)) === false) || ($ts < 0)) {
+    $d = explode(' ', $date);
+    array_pop($d);
+    if (!$d) break;
+    $date = implode(' ', $d);
+  }
+
+  return $ts;
+}
+
+
+/**
  * Convert the given date to a human readable form
  * This uses the date formatting properties from config
  *
@@ -991,22 +1022,8 @@
   
   $ts = NULL;
 
-  if (is_numeric($date))
-    $ts = $date;
-  else if (!empty($date))
-    {
-    // support non-standard "GMTXXXX" literal
-    $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date);
-    // if date parsing fails, we have a date in non-rfc format.
-    // remove token from the end and try again
-    while ((($ts = @strtotime($date))===false) || ($ts < 0))
-      {
-        $d = explode(' ', $date);
-        array_pop($d);
-        if (!$d) break;
-        $date = implode(' ', $d);
-      }
-    }
+  if (!empty($date))
+    $ts = rcube_strtotime($date);
 
   if (empty($ts))
     return '';

Modified: trunk/roundcubemail/program/include/rcube_imap_generic.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_imap_generic.php	2011-01-21 11:46:49 UTC (rev 4438)
+++ trunk/roundcubemail/program/include/rcube_imap_generic.php	2011-01-21 16:50:07 UTC (rev 4439)
@@ -3223,21 +3223,7 @@
      */
     private function strToTime($date)
     {
-        // support non-standard "GMTXXXX" literal
-        $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date);
-        // if date parsing fails, we have a date in non-rfc format.
-        // remove token from the end and try again
-        while ((($ts = @strtotime($date))===false) || ($ts < 0)) {
-            $d = explode(' ', $date);
-            array_pop($d);
-            if (!$d) {
-                break;
-            }
-            $date = implode(' ', $d);
-        }
-
-        $ts = (int) $ts;
-
+        $ts = (int) rcube_strtotime($date);
         return $ts < 0 ? 0 : $ts;
     }
 

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list