Skip to content

Commit 3042a0a

Browse files
committed
DateTimeControl: default date for 'time' is 0001-01-01
1 parent 0d30e58 commit 3042a0a

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/Forms/Controls/DateTimeControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private function normalizeValue($value): \DateTimeImmutable
107107
if ($this->type === self::TypeDate) {
108108
return $dt->setTime(0, 0);
109109
} elseif ($this->type === self::TypeTime) {
110-
return $dt->setDate(0, 1, 1)->setTime($h, $m, $s);
110+
return $dt->setDate(1, 1, 1)->setTime($h, $m, $s);
111111
} elseif ($this->type === self::TypeDateTime) {
112112
return $dt->setTime($h, $m, $s);
113113
}

tests/Forms/Controls.DateTimeControl.loadData.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ test('valid time', function () {
105105
$_POST = ['time' => '10:22:33.44'];
106106
$form = new Form;
107107
$input = $form->addTime('time');
108-
Assert::equal(new DateTimeImmutable('0000-01-01 10:22'), $input->getValue());
108+
Assert::equal(new DateTimeImmutable('0001-01-01 10:22'), $input->getValue());
109109
Assert::true($input->isFilled());
110110
});
111111

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

tests/Forms/Controls.DateTimeControl.value.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ test('time as DateTime object', function () {
8484
$input = $form->addTime('time')
8585
->setValue(new Nette\Utils\DateTime('2023-10-05 11:22:33.44'));
8686

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

9090

0 commit comments

Comments
 (0)