summaryrefslogtreecommitdiff
path: root/program/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-08-24 18:08:54 +0200
committerAleksander Machniak <alec@alec.pl>2013-08-24 18:20:03 +0200
commit4db26a430b0a2fb9b5c725aef373c6b79e27f100 (patch)
treed8113c0b2bddc53cb5393840da2f49368d5bc850 /program/lib
parent6e14fcf9bfb0bf3ee237dc7516655f55c8436a3a (diff)
Fix handling of non-default date formats (#1489294)
- remove ambiguous m/d/Y format from default config Conflicts: CHANGELOG config/main.inc.php.dist program/lib/Roundcube/rcube_utils.php tests/Framework/Utils.php
Diffstat (limited to 'program/lib')
-rw-r--r--program/lib/Roundcube/rcube_utils.php35
1 files changed, 28 insertions, 7 deletions
diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php
index f252fd9b9..81b6a9b18 100644
--- a/program/lib/Roundcube/rcube_utils.php
+++ b/program/lib/Roundcube/rcube_utils.php
@@ -717,16 +717,37 @@ class rcube_utils
*/
public static function strtotime($date)
{
+ $date = trim($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]));
+ if (preg_match('/^([12][90]\d\d)([01]\d)([0123]\d)$/', $date, $m)) {
+ return mktime(0,0,0, intval($m[2]), intval($m[3]), intval($m[1]));
}
- else if (is_numeric($date)) {
- return $date;
+
+ // common little-endian formats, e.g. dd/mm/yyyy (not all are supported by strtotime)
+ if (preg_match('/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{4})$/', $date, $m)
+ && $m[1] > 0 && $m[1] <= 31 && $m[2] > 0 && $m[2] <= 12 && $m[3] >= 1970
+ ) {
+ return mktime(0,0,0, intval($m[2]), intval($m[1]), intval($m[3]));
}
- // support non-standard "GMTXXXX" literal
- $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date);
+ // unix timestamp
+ if (is_numeric($date)) {
+ return (int) $date;
+ }
+
+ // Clean malformed data
+ $date = preg_replace(
+ array(
+ '/GMT\s*([+-][0-9]+)/', // support non-standard "GMTXXXX" literal
+ '/[^a-z0-9\x20\x09:+-]/i', // remove any invalid characters
+ '/\s*(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s*/i', // remove weekday names
+ ),
+ array(
+ '\\1',
+ '',
+ '',
+ ), $date);
// if date parsing fails, we have a date in non-rfc format.
// remove token from the end and try again
@@ -739,7 +760,7 @@ class rcube_utils
$date = implode(' ', $d);
}
- return $ts;
+ return (int) $ts;
}