Consider the configured date format when parsing date/time values for tasks (#2801) + reduce code-duplication
This commit is contained in:
parent
028c21f4ca
commit
01c6a75d16
1 changed files with 29 additions and 18 deletions
|
@ -381,27 +381,11 @@ class tasklist extends rcube_plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($rec['date'])) {
|
if (!empty($rec['date'])) {
|
||||||
try {
|
$this->normalize_dates($rec, 'date', 'time');
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($rec['startdate'])) {
|
if (!empty($rec['startdate'])) {
|
||||||
try {
|
$this->normalize_dates($rec, 'startdate', 'starttime');
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert tags to array, filter out empty entries
|
// convert tags to array, filter out empty entries
|
||||||
|
@ -434,6 +418,33 @@ class tasklist extends rcube_plugin
|
||||||
return $rec;
|
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
|
* Releases some resources after successful save
|
||||||
|
|
Loading…
Add table
Reference in a new issue