Skip to content

Commit

Permalink
DateTimeControl: default date for 'time' is 0001-01-01
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 21, 2024
1 parent 0d30e58 commit 3042a0a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Forms/Controls/DateTimeControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function normalizeValue($value): \DateTimeImmutable
if ($this->type === self::TypeDate) {
return $dt->setTime(0, 0);
} elseif ($this->type === self::TypeTime) {
return $dt->setDate(0, 1, 1)->setTime($h, $m, $s);
return $dt->setDate(1, 1, 1)->setTime($h, $m, $s);
} elseif ($this->type === self::TypeDateTime) {
return $dt->setTime($h, $m, $s);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Forms/Controls.DateTimeControl.loadData.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test('valid time', function () {
$_POST = ['time' => '10:22:33.44'];
$form = new Form;
$input = $form->addTime('time');
Assert::equal(new DateTimeImmutable('0000-01-01 10:22'), $input->getValue());
Assert::equal(new DateTimeImmutable('0001-01-01 10:22'), $input->getValue());
Assert::true($input->isFilled());
});

Expand All @@ -114,7 +114,7 @@ test('valid time with seconds', function () {
$_POST = ['time' => '10:22:33.44'];
$form = new Form;
$input = $form->addTime('time', null, true);
Assert::equal(new DateTimeImmutable('0000-01-01 10:22:33'), $input->getValue());
Assert::equal(new DateTimeImmutable('0001-01-01 10:22:33'), $input->getValue());
Assert::true($input->isFilled());
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/Controls.DateTimeControl.value.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ test('time as DateTime object', function () {
$input = $form->addTime('time')
->setValue(new Nette\Utils\DateTime('2023-10-05 11:22:33.44'));

Assert::equal(new DateTimeImmutable('0000-01-01 11:22'), $input->getValue());
Assert::equal(new DateTimeImmutable('0001-01-01 11:22'), $input->getValue());
});


Expand Down

0 comments on commit 3042a0a

Please sign in to comment.