Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9b89b2e

Browse filesBrowse files
bug #41000 [Form] Use !isset for checks cause this doesn't falsely include 0 (Kai Dederichs)
This PR was submitted for the 5.2 branch but it was squashed and merged into the 4.4 branch instead. Discussion ---------- [Form] Use !isset for checks cause this doesn't falsely include 0 | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #40999 | License | MIT By using isset 0 won't falsely included anymore Commits ------- cd541c5 [Form] Use !isset for checks cause this doesn't falsely include 0
2 parents 11a8837 + cd541c5 commit 9b89b2e
Copy full SHA for 9b89b2e

File tree

3 files changed

+51
-3
lines changed
Filter options

3 files changed

+51
-3
lines changed

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ public function reverseTransform($value)
170170
empty($value['year']) ? $this->referenceDate->format('Y') : $value['year'],
171171
empty($value['month']) ? $this->referenceDate->format('m') : $value['month'],
172172
empty($value['day']) ? $this->referenceDate->format('d') : $value['day'],
173-
empty($value['hour']) ? $this->referenceDate->format('H') : $value['hour'],
174-
empty($value['minute']) ? $this->referenceDate->format('i') : $value['minute'],
175-
empty($value['second']) ? $this->referenceDate->format('s') : $value['second']
173+
$value['hour'] ?? $this->referenceDate->format('H'),
174+
$value['minute'] ?? $this->referenceDate->format('i'),
175+
$value['second'] ?? $this->referenceDate->format('s')
176176
),
177177
new \DateTimeZone($this->outputTimezone)
178178
);

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,32 @@ public function testSubmitFromSingleTextRaw()
204204
$this->assertEquals('02.06.2010', $form->getViewData());
205205
}
206206

207+
public function testArrayDateWithReferenceDoesUseReferenceTimeOnZero()
208+
{
209+
// we test against "de_DE", so we need the full implementation
210+
IntlTestHelper::requireFullIntl($this, false);
211+
212+
\Locale::setDefault('de_DE');
213+
214+
$input = [
215+
'day' => '0',
216+
'month' => '0',
217+
'year' => '0',
218+
];
219+
220+
$form = $this->factory->create(static::TESTED_TYPE, $input, [
221+
'format' => \IntlDateFormatter::MEDIUM,
222+
'html5' => false,
223+
'model_timezone' => 'UTC',
224+
'view_timezone' => 'Europe/Berlin',
225+
'input' => 'array',
226+
'widget' => 'single_text',
227+
]);
228+
229+
$this->assertSame($input, $form->getData());
230+
$this->assertEquals('01.01.1970', $form->getViewData());
231+
}
232+
207233
public function testSubmitFromText()
208234
{
209235
$form = $this->factory->create(static::TESTED_TYPE, null, [

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,28 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = [], $expectedDat
969969
$this->assertSame($expectedData, $form->getData());
970970
}
971971

972+
public function testArrayTimeWithReferenceDoesNotUseReferenceTimeOnZero()
973+
{
974+
$form = $this->factory->create(static::TESTED_TYPE, null, [
975+
'model_timezone' => 'UTC',
976+
'view_timezone' => 'Europe/Berlin',
977+
'reference_date' => new \DateTimeImmutable('01-01-2021 12:34:56', new \DateTimeZone('UTC')),
978+
'input' => 'array',
979+
]);
980+
981+
$input = [
982+
'hour' => '0',
983+
'minute' => '0',
984+
];
985+
$form->submit($input);
986+
987+
$this->assertEquals([
988+
'hour' => '23',
989+
'minute' => '0',
990+
], $form->getData());
991+
$this->assertSame($input, $form->getViewData());
992+
}
993+
972994
/**
973995
* @dataProvider provideEmptyData
974996
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.