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 639b74d

Browse filesBrowse files
bug #40998 [Form] Use reference date in reverse transform (KDederichs)
This PR was merged into the 4.4 branch. Discussion ---------- [Form] Use reference date in reverse transform | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #40997 | License | MIT Use reference time in reverse transform to fix the display inconsistancies Commits ------- 1a368fc Use reference date in reverse transform Fixes #40997
2 parents 76f6d74 + 1a368fc commit 639b74d
Copy full SHA for 639b74d

File tree

Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed

‎src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
204204
));
205205
} elseif ('array' === $options['input']) {
206206
$builder->addModelTransformer(new ReversedTransformer(
207-
new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], $parts)
207+
new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], $parts, 'text' === $options['widget'], $options['reference_date'])
208208
));
209209
}
210210
}

‎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
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,27 @@ public function testArrayTimeWithReferenceDoesNotUseReferenceTimeOnZero()
991991
$this->assertSame($input, $form->getViewData());
992992
}
993993

994+
public function testArrayTimeWithReferenceDoesUseReferenceDateOnModelTransform()
995+
{
996+
$input = [
997+
'hour' => '21',
998+
'minute' => '45',
999+
];
1000+
1001+
$form = $this->factory->create(static::TESTED_TYPE, $input, [
1002+
'model_timezone' => 'UTC',
1003+
'view_timezone' => 'Europe/Berlin',
1004+
'reference_date' => new \DateTimeImmutable('01-05-2021 12:34:56', new \DateTimeZone('UTC')),
1005+
'input' => 'array',
1006+
]);
1007+
1008+
$this->assertSame($input, $form->getData());
1009+
$this->assertEquals([
1010+
'hour' => '23',
1011+
'minute' => '45',
1012+
], $form->getViewData());
1013+
}
1014+
9941015
/**
9951016
* @dataProvider provideEmptyData
9961017
*/

0 commit comments

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