diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | app/Core/DateParser.php | 4 | ||||
-rw-r--r-- | app/Model/ProjectModel.php | 8 | ||||
-rw-r--r-- | app/Template/project_edit/dates.php | 8 | ||||
-rw-r--r-- | tests/units/Core/DateParserTest.php | 3 | ||||
-rw-r--r-- | tests/units/Model/ProjectModelTest.php | 18 |
6 files changed, 37 insertions, 6 deletions
@@ -28,6 +28,8 @@ Bug fixes: * Fix undefined constant in config example file * Fix PHP notice when sending overdue notifications +* Fix wrong project date format (shown as 01/01/1970) + - If the dates still not correct, modify and save the date Version 1.0.32 -------------- diff --git a/app/Core/DateParser.php b/app/Core/DateParser.php index a7b10a7a..5d770241 100644 --- a/app/Core/DateParser.php +++ b/app/Core/DateParser.php @@ -304,6 +304,10 @@ class DateParser extends Base { foreach ($fields as $field) { if (! empty($values[$field])) { + if (! ctype_digit($values[$field])) { + $values[$field] = strtotime($values[$field]); + } + $values[$field] = date($format, $values[$field]); } else { $values[$field] = ''; diff --git a/app/Model/ProjectModel.php b/app/Model/ProjectModel.php index d2019b72..aba5eee2 100644 --- a/app/Model/ProjectModel.php +++ b/app/Model/ProjectModel.php @@ -419,6 +419,14 @@ class ProjectModel extends Base $values['identifier'] = strtoupper($values['identifier']); } + if (! empty($values['start_date'])) { + $values['start_date'] = $this->dateParser->getIsoDate($values['start_date']); + } + + if (! empty($values['end_date'])) { + $values['end_date'] = $this->dateParser->getIsoDate($values['end_date']); + } + $this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end')); return $this->exists($values['id']) && diff --git a/app/Template/project_edit/dates.php b/app/Template/project_edit/dates.php index 48135ddc..1c2c3dd4 100644 --- a/app/Template/project_edit/dates.php +++ b/app/Template/project_edit/dates.php @@ -11,12 +11,8 @@ <?= $this->form->csrf() ?> <?= $this->form->hidden('id', $values) ?> <?= $this->form->hidden('name', $values) ?> - - <?= $this->form->label(t('Start date'), 'start_date') ?> - <?= $this->form->text('start_date', $values, $errors, array('maxlength="10"'), 'form-date') ?> - - <?= $this->form->label(t('End date'), 'end_date') ?> - <?= $this->form->text('end_date', $values, $errors, array('maxlength="10"'), 'form-date') ?> + <?= $this->form->date(t('Start date'), 'start_date', $values, $errors) ?> + <?= $this->form->date(t('End date'), 'end_date', $values, $errors) ?> <div class="form-actions"> <button type="submit" class="btn btn-blue"><?= t('Save') ?></button> diff --git a/tests/units/Core/DateParserTest.php b/tests/units/Core/DateParserTest.php index fbde8bd5..ee4e2d54 100644 --- a/tests/units/Core/DateParserTest.php +++ b/tests/units/Core/DateParserTest.php @@ -212,6 +212,9 @@ class DateParserTest extends Base $this->assertEquals(array('date' => '06/02/2016'), $dateParser->format($values, array('date'), 'd/m/Y')); $this->assertEquals(array('date' => '02/06/2016 7:30 pm'), $dateParser->format($values, array('date'), 'm/d/Y g:i a')); + + $values['date'] = '2016-02-06'; + $this->assertEquals(array('date' => '06/02/2016'), $dateParser->format($values, array('date'), 'd/m/Y')); } public function testConvert() diff --git a/tests/units/Model/ProjectModelTest.php b/tests/units/Model/ProjectModelTest.php index 81e0dd57..cd86b654 100644 --- a/tests/units/Model/ProjectModelTest.php +++ b/tests/units/Model/ProjectModelTest.php @@ -39,6 +39,24 @@ class ProjectModelTest extends Base $this->assertEquals(0, $project['is_private']); $this->assertEquals(time(), $project['last_modified'], '', 1); $this->assertEmpty($project['token']); + $this->assertEmpty($project['start_date']); + $this->assertEmpty($project['end_date']); + } + + public function testProjectDate() + { + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertTrue($projectModel->update(array( + 'id' => 1, + 'start_date' => '2016-08-31', + 'end_date' => '08/31/2016', + ))); + + $project = $projectModel->getById(1); + $this->assertEquals('2016-08-31', $project['start_date']); + $this->assertEquals('2016-08-31', $project['end_date']); } public function testCreationWithDuplicateName() |