diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-06-05 21:28:56 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-06-05 21:28:56 -0400 |
commit | 656f4306325d7944280ce111d95aeaeacab8d3cd (patch) | |
tree | 9fe6e6631b2b1d14feb1344e2b78186db9a07a04 /app | |
parent | 33098e4e11ba451d0b4fed7f8f41820e2bb66bd4 (diff) |
Changed DateParser to use only user format and ISO-8601
Diffstat (limited to 'app')
-rw-r--r-- | app/Controller/TaskModificationController.php | 5 | ||||
-rw-r--r-- | app/Controller/TaskViewController.php | 2 | ||||
-rw-r--r-- | app/Core/DateParser.php | 66 | ||||
-rw-r--r-- | app/Export/TransitionExport.php | 2 | ||||
-rw-r--r-- | app/Validator/TaskValidator.php | 4 |
5 files changed, 65 insertions, 14 deletions
diff --git a/app/Controller/TaskModificationController.php b/app/Controller/TaskModificationController.php index fc9113dd..50583df4 100644 --- a/app/Controller/TaskModificationController.php +++ b/app/Controller/TaskModificationController.php @@ -91,11 +91,10 @@ class TaskModificationController extends BaseController $values = $task; $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); $values = $this->hook->merge('controller:task-modification:form:default', $values, array('default_values' => $values)); + $values = $this->dateParser->format($values, array('date_due'), $this->dateParser->getUserDateFormat()); + $values = $this->dateParser->format($values, array('date_started'), $this->dateParser->getUserDateTimeFormat()); } - $values = $this->dateParser->format($values, array('date_due'), $this->configModel->get('application_date_format', DateParser::DATE_FORMAT)); - $values = $this->dateParser->format($values, array('date_started'), $this->configModel->get('application_datetime_format', DateParser::DATE_TIME_FORMAT)); - $this->response->html($this->template->render('task_modification/edit_task', array( 'project' => $project, 'values' => $values, diff --git a/app/Controller/TaskViewController.php b/app/Controller/TaskViewController.php index 2a79ee45..073434b2 100644 --- a/app/Controller/TaskViewController.php +++ b/app/Controller/TaskViewController.php @@ -70,7 +70,7 @@ class TaskViewController extends BaseController 'time_spent' => $task['time_spent'] ?: '', ); - $values = $this->dateParser->format($values, array('date_started'), $this->configModel->get('application_datetime_format', DateParser::DATE_TIME_FORMAT)); + $values = $this->dateParser->format($values, array('date_started'), $this->dateParser->getUserDateTimeFormat()); $this->response->html($this->helper->layout->task('task/show', array( 'task' => $task, diff --git a/app/Core/DateParser.php b/app/Core/DateParser.php index 835eb3e3..bdab7998 100644 --- a/app/Core/DateParser.php +++ b/app/Core/DateParser.php @@ -16,6 +16,28 @@ class DateParser extends Base const DATE_TIME_FORMAT = 'm/d/Y H:i'; /** + * Get date format from settings + * + * @access public + * @return string + */ + public function getUserDateFormat() + { + return $this->configModel->get('application_date_format', DateParser::DATE_FORMAT); + } + + /** + * Get date time format from settings + * + * @access public + * @return string + */ + public function getUserDateTimeFormat() + { + return $this->configModel->get('application_datetime_format', DateParser::DATE_TIME_FORMAT); + } + + /** * List of time formats * * @access public @@ -38,19 +60,29 @@ class DateParser extends Base */ public function getDateFormats($iso = false) { - $iso_formats = array( + $formats = array( + $this->getUserDateFormat(), + ); + + $isoFormats = array( 'Y-m-d', 'Y_m_d', ); - $user_formats = array( + $userFormats = array( 'm/d/Y', 'd/m/Y', 'Y/m/d', 'd.m.Y', ); - return $iso ? array_merge($iso_formats, $user_formats) : $user_formats; + if ($iso) { + $formats = array_merge($formats, $isoFormats, $userFormats); + } else { + $formats = array_merge($formats, $userFormats); + } + + return array_unique($formats); } /** @@ -62,7 +94,9 @@ class DateParser extends Base */ public function getDateTimeFormats($iso = false) { - $formats = array(); + $formats = array( + $this->getUserDateTimeFormat(), + ); foreach ($this->getDateFormats($iso) as $date) { foreach ($this->getTimeFormats() as $time) { @@ -70,7 +104,7 @@ class DateParser extends Base } } - return $formats; + return array_unique($formats); } /** @@ -97,13 +131,31 @@ class DateParser extends Base $values = array(); foreach ($formats as $format) { - $values[$format] = date($format); + $values[$format] = date($format).' ('.$format.')'; } return $values; } /** + * Get formats for date parsing + * + * @access public + * @return array + */ + public function getParserFormats() + { + return array( + $this->getUserDateFormat(), + 'Y-m-d', + 'Y_m_d', + $this->getUserDateTimeFormat(), + 'Y-m-d H:i', + 'Y_m_d H:i', + ); + } + + /** * Parse a date and return a unix timestamp, try different date formats * * @access public @@ -116,7 +168,7 @@ class DateParser extends Base return (int) $value; } - foreach ($this->getAllDateFormats(true) as $format) { + foreach ($this->getParserFormats() as $format) { $timestamp = $this->getValidDate($value, $format); if ($timestamp !== 0) { diff --git a/app/Export/TransitionExport.php b/app/Export/TransitionExport.php index 0df1f70e..5399edd8 100644 --- a/app/Export/TransitionExport.php +++ b/app/Export/TransitionExport.php @@ -68,7 +68,7 @@ class TransitionExport extends Base $transition['src_column'], $transition['dst_column'], $transition['name'] ?: $transition['username'], - date($this->configModel->get('application_datetime_format', DateParser::DATE_TIME_FORMAT), $transition['date']), + date($this->dateParser->getUserDateTimeFormat(), $transition['date']), round($transition['time_spent'] / 3600, 2) ); diff --git a/app/Validator/TaskValidator.php b/app/Validator/TaskValidator.php index 7c39ff51..90bda6f3 100644 --- a/app/Validator/TaskValidator.php +++ b/app/Validator/TaskValidator.php @@ -40,8 +40,8 @@ class TaskValidator extends BaseValidator new Validators\Integer('priority', t('This value must be an integer')), new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200), new Validators\MaxLength('reference', t('The maximum length is %d characters', 50), 50), - new Validators\Date('date_due', t('Invalid date'), $this->dateParser->getDateFormats(true)), - new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getDateTimeFormats(true)), + new Validators\Date('date_due', t('Invalid date'), $this->dateParser->getParserFormats()), + new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getParserFormats()), new Validators\Numeric('time_spent', t('This value must be numeric')), new Validators\Numeric('time_estimated', t('This value must be numeric')), ); |