Fix wrong project date format (shown as 01/01/1970)

This commit is contained in:
Frederic Guillot
2016-08-31 21:04:22 -04:00
parent 12acf66ad2
commit 3861e90336
6 changed files with 37 additions and 6 deletions

View File

@@ -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
--------------

View File

@@ -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] = '';

View File

@@ -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']) &&

View File

@@ -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>

View File

@@ -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()

View File

@@ -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()