summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2014-01-27 10:54:45 (GMT)
committerThomas Bruederli <thomas@roundcube.net>2014-01-27 10:57:33 (GMT)
commit160ab0c89568b98940f84a144c53b9e32dea221f (patch)
treee0a349555ebe7f0071b1703c630e6d41fde6d1e9
parenta88c0771628d413eb6eaaa10139163824cfd453a (diff)
downloadroundcubemail-plugins-kolab-roundcubemail-plugins-kolab-3.1.11.tar.gz
Consider the configured date format when parsing date/time values for tasks (#2801) + reduce code-duplicationroundcubemail-plugins-kolab-3.1.11
-rw-r--r--plugins/tasklist/tasklist.php47
1 files changed, 29 insertions, 18 deletions
diff --git a/plugins/tasklist/tasklist.php b/plugins/tasklist/tasklist.php
index c865db0..e96f82f 100644
--- a/plugins/tasklist/tasklist.php
+++ b/plugins/tasklist/tasklist.php
@@ -381,27 +381,11 @@ class tasklist extends rcube_plugin
}
if (!empty($rec['date'])) {
- try {
- $date = new DateTime($rec['date'] . ' ' . $rec['time'], $this->timezone);
- $rec['date'] = $date->format('Y-m-d');
- if (!empty($rec['time']))
- $rec['time'] = $date->format('H:i');
- }
- catch (Exception $e) {
- $rec['date'] = $rec['time'] = null;
- }
+ $this->normalize_dates($rec, 'date', 'time');
}
if (!empty($rec['startdate'])) {
- try {
- $date = new DateTime($rec['startdate'] . ' ' . $rec['starttime'], $this->timezone);
- $rec['startdate'] = $date->format('Y-m-d');
- if (!empty($rec['starttime']))
- $rec['starttime'] = $date->format('H:i');
- }
- catch (Exception $e) {
- $rec['startdate'] = $rec['starttime'] = null;
- }
+ $this->normalize_dates($rec, 'startdate', 'starttime');
}
// convert tags to array, filter out empty entries
@@ -434,6 +418,33 @@ class tasklist extends rcube_plugin
return $rec;
}
+ /**
+ * Utility method to convert a tasks date/time values into a normalized format
+ */
+ private function normalize_dates(&$rec, $date_key, $time_key)
+ {
+ try {
+ // parse date from user format (#2801)
+ $date_format = $this->rc->config->get(empty($rec[$time_key]) ? 'date_format' : 'date_long', 'Y-m-d');
+ $date = DateTime::createFromFormat($date_format, trim($rec[$date_key] . ' ' . $rec[$time_key]), $this->timezone);
+
+ // fall back to default strtotime logic
+ if (empty($date)) {
+ $date = new DateTime($rec[$date_key] . ' ' . $rec[$time_key], $this->timezone);
+ }
+
+ $rec[$date_key] = $date->format('Y-m-d');
+ if (!empty($rec[$time_key]))
+ $rec[$time_key] = $date->format('H:i');
+
+ return true;
+ }
+ catch (Exception $e) {
+ $rec[$date_key] = $rec[$time_key] = null;
+ }
+
+ return false;
+ }
/**
* Releases some resources after successful save