summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-07-07 19:15:53 -0400
committerFrederic Guillot <fred@kanboard.net>2015-07-07 19:15:53 -0400
commit58297ca3b11b9ad526a8ac344e5ac56d9e1b5a13 (patch)
treec20ff7b7463e0fa97667a2f17c482c85e015f7e3 /app
parent5e7e03a866459047b677e57be33eee991aa57214 (diff)
Add datetime picker for start date
Diffstat (limited to 'app')
-rw-r--r--app/Controller/Task.php2
-rw-r--r--app/Model/DateParser.php51
-rw-r--r--app/Model/TaskCreation.php3
-rw-r--r--app/Model/TaskModification.php3
-rw-r--r--app/Model/TaskValidator.php2
-rw-r--r--app/Template/task/time.php2
6 files changed, 49 insertions, 14 deletions
diff --git a/app/Controller/Task.php b/app/Controller/Task.php
index 2d4f783a..bb859679 100644
--- a/app/Controller/Task.php
+++ b/app/Controller/Task.php
@@ -64,7 +64,7 @@ class Task extends Base
'time_spent' => $task['time_spent'] ?: '',
);
- $this->dateParser->format($values, array('date_started'));
+ $this->dateParser->format($values, array('date_started'), 'Y-m-d H:i');
$this->response->html($this->taskLayout('task/show', array(
'project' => $this->project->getById($task['project_id']),
diff --git a/app/Model/DateParser.php b/app/Model/DateParser.php
index be79a92e..79a8385c 100644
--- a/app/Model/DateParser.php
+++ b/app/Model/DateParser.php
@@ -85,8 +85,7 @@ class DateParser extends Base
*/
public function getTimestamp($value)
{
- foreach ($this->getDateFormats() as $format) {
-
+ foreach ($this->getAllFormats() as $format) {
$timestamp = $this->getValidDate($value, $format);
if ($timestamp !== 0) {
@@ -98,6 +97,25 @@ class DateParser extends Base
}
/**
+ * Get all combinations of date/time formats
+ *
+ * @access public
+ * @return []string
+ */
+ public function getAllFormats()
+ {
+ $formats = array();
+
+ foreach ($this->getDateFormats() as $date) {
+ foreach ($this->getTimeFormats() as $time) {
+ $formats[] = $date.' '.$time;
+ }
+ }
+
+ return array_merge($formats, $this->getDateFormats());
+ }
+
+ /**
* Return the list of supported date formats (for the parser)
*
* @access public
@@ -113,6 +131,21 @@ class DateParser extends Base
}
/**
+ * Return the list of supported time formats (for the parser)
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getTimeFormats()
+ {
+ return array(
+ 'H:i',
+ 'g:i A',
+ 'g:iA',
+ );
+ }
+
+ /**
* Return the list of available date formats (for the config page)
*
* @access public
@@ -143,7 +176,7 @@ class DateParser extends Base
* Get a timetstamp from an ISO date format
*
* @access public
- * @param string $date Date format
+ * @param string $date
* @return integer
*/
public function getTimestampFromIsoFormat($date)
@@ -166,7 +199,6 @@ class DateParser extends Base
}
foreach ($fields as $field) {
-
if (! empty($values[$field])) {
$values[$field] = date($format, $values[$field]);
}
@@ -180,15 +212,16 @@ class DateParser extends Base
* Convert date (form input data)
*
* @access public
- * @param array $values Database values
- * @param string[] $fields Date fields
+ * @param array $values Database values
+ * @param string[] $fields Date fields
+ * @param boolean $keep_time Keep time or not
*/
- public function convert(array &$values, array $fields)
+ public function convert(array &$values, array $fields, $keep_time = false)
{
foreach ($fields as $field) {
-
if (! empty($values[$field]) && ! is_numeric($values[$field])) {
- $values[$field] = $this->removeTimeFromTimestamp($this->getTimestamp($values[$field]));
+ $timestamp = $this->getTimestamp($values[$field]);
+ $values[$field] = $keep_time ? $timestamp : $this->removeTimeFromTimestamp($timestamp);
}
}
}
diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreation.php
index 893cbc43..b444a190 100644
--- a/app/Model/TaskCreation.php
+++ b/app/Model/TaskCreation.php
@@ -43,7 +43,8 @@ class TaskCreation extends Base
*/
public function prepare(array &$values)
{
- $this->dateParser->convert($values, array('date_due', 'date_started'));
+ $this->dateParser->convert($values, array('date_due'));
+ $this->dateParser->convert($values, array('date_started'), true);
$this->removeFields($values, array('another_task'));
$this->resetFields($values, array('owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated'));
diff --git a/app/Model/TaskModification.php b/app/Model/TaskModification.php
index 4691ce81..b67106e1 100644
--- a/app/Model/TaskModification.php
+++ b/app/Model/TaskModification.php
@@ -83,7 +83,8 @@ class TaskModification extends Base
*/
public function prepare(array &$values)
{
- $this->dateParser->convert($values, array('date_due', 'date_started'));
+ $this->dateParser->convert($values, array('date_due'));
+ $this->dateParser->convert($values, array('date_started'), true);
$this->removeFields($values, array('another_task', 'id'));
$this->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent'));
$this->convertIntegerFields($values, array('is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate'));
diff --git a/app/Model/TaskValidator.php b/app/Model/TaskValidator.php
index ec1383ad..95b8a26c 100644
--- a/app/Model/TaskValidator.php
+++ b/app/Model/TaskValidator.php
@@ -39,7 +39,7 @@ class TaskValidator extends Base
new Validators\Integer('recurrence_status', t('This value must be an integer')),
new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200),
new Validators\Date('date_due', t('Invalid date'), $this->dateParser->getDateFormats()),
- new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getDateFormats()),
+ new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getAllFormats()),
new Validators\Numeric('time_spent', t('This value must be numeric')),
new Validators\Numeric('time_estimated', t('This value must be numeric')),
);
diff --git a/app/Template/task/time.php b/app/Template/task/time.php
index 6682a08d..9e024c7f 100644
--- a/app/Template/task/time.php
+++ b/app/Template/task/time.php
@@ -3,7 +3,7 @@
<?= $this->form->hidden('id', $values) ?>
<?= $this->form->label(t('Start date'), 'date_started') ?>
- <?= $this->form->text('date_started', $values, array(), array('placeholder="'.$this->text->in($date_format, $date_formats).'"'), 'form-date') ?>
+ <?= $this->form->text('date_started', $values, array(), array('placeholder="'.$this->text->in($date_format, $date_formats).'"'), 'form-datetime') ?>
<?= $this->form->label(t('Time estimated'), 'time_estimated') ?>
<?= $this->form->numeric('time_estimated', $values, array(), array('placeholder="'.t('hours').'"')) ?>