From acba6839a6082e3e3800a733f8baea7c843fc02e Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 11 Oct 2014 21:11:10 -0400 Subject: Add 3 new fields for tasks: start date, time estimated and time spent --- app/Model/DateParser.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'app/Model/DateParser.php') diff --git a/app/Model/DateParser.php b/app/Model/DateParser.php index 88e67686..38265f98 100644 --- a/app/Model/DateParser.php +++ b/app/Model/DateParser.php @@ -97,4 +97,46 @@ class DateParser extends Base { return mktime(0, 0, 0, date('m', $timestamp), date('d', $timestamp), date('Y', $timestamp)); } + + /** + * Format date (form display) + * + * @access public + * @param array $values Database values + * @param array $fields Date fields + * @param string $format Date format + */ + public function format(array &$values, array $fields, $format = '') + { + if ($format === '') { + $format = $this->config->get('application_date_format'); + } + + foreach ($fields as $field) { + + if (! empty($values[$field])) { + $values[$field] = date($format, $values[$field]); + } + else { + $values[$field] = ''; + } + } + } + + /** + * Convert date (form input data) + * + * @access public + * @param array $values Database values + * @param array $fields Date fields + */ + public function convert(array &$values, array $fields) + { + foreach ($fields as $field) { + + if (! empty($values[$field]) && ! is_numeric($values[$field])) { + $values[$field] = $this->getTimestamp($values[$field]); + } + } + } } -- cgit v1.2.3