summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-01-21 16:50:07 +0000
committerthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-01-21 16:50:07 +0000
commit7139f105f32ffa048b17fd7e27f1dcff44e8bda1 (patch)
tree0bb2146790936a7118f58480ae202f666bf77f9e
parent7d1d40e5d04a9b01d9ecd57d235e862438bac526 (diff)
Use improved strtotime() function + reduce duplicated code
git-svn-id: https://svn.roundcube.net/trunk@4439 208e9e7b-5314-0410-a742-e7e81cd9613c
-rw-r--r--roundcubemail/program/include/main.inc49
-rw-r--r--roundcubemail/program/include/rcube_imap_generic.php16
2 files changed, 34 insertions, 31 deletions
diff --git a/roundcubemail/program/include/main.inc b/roundcubemail/program/include/main.inc
index 0815c259f..8e8de03a3 100644
--- a/roundcubemail/program/include/main.inc
+++ b/roundcubemail/program/include/main.inc
@@ -978,6 +978,37 @@ function parse_attrib_string($str)
/**
+ * 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 @@ function format_date($date, $format=NULL)
$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 '';
diff --git a/roundcubemail/program/include/rcube_imap_generic.php b/roundcubemail/program/include/rcube_imap_generic.php
index 6bebd8c7b..b4f01a9e2 100644
--- a/roundcubemail/program/include/rcube_imap_generic.php
+++ b/roundcubemail/program/include/rcube_imap_generic.php
@@ -3223,21 +3223,7 @@ class rcube_imap_generic
*/
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;
}