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 031d8c2

Browse filesBrowse files
committed
[Form] DateTimeToLocalizedStringTransformer does not use TZ when using only date
1 parent e9f2512 commit 031d8c2
Copy full SHA for 031d8c2

File tree

2 files changed

+13
-4
lines changed
Filter options

2 files changed

+13
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ public function reverseTransform($value)
130130
try {
131131
if ($dateOnly) {
132132
// we only care about year-month-date, which has been delivered as a timestamp pointing to UTC midnight
133-
return new \DateTime(gmdate('Y-m-d', $timestamp), new \DateTimeZone($this->inputTimezone));
133+
$dateTime = new \DateTime(gmdate('Y-m-d', $timestamp), new \DateTimeZone($this->outputTimezone));
134+
} else {
135+
// read timestamp into DateTime object - the formatter delivers a timestamp
136+
$dateTime = new \DateTime(sprintf('@%s', $timestamp));
134137
}
135-
136-
// read timestamp into DateTime object - the formatter delivers a timestamp
137-
$dateTime = new \DateTime(sprintf('@%s', $timestamp));
138138
// set timezone separately, as it would be ignored if set via the constructor,
139139
// see http://php.net/manual/en/datetime.construct.php
140140
$dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));

‎src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ public function testReverseTransformWithDifferentTimezones()
240240
$this->assertDateTimeEquals($dateTime, $transformer->reverseTransform('03.02.2010, 04:05'));
241241
}
242242

243+
public function testReverseTransformOnlyDateWithDifferentTimezones()
244+
{
245+
$transformer = new DateTimeToLocalizedStringTransformer('Europe/Berlin', 'Pacific/Tahiti', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd');
246+
247+
$dateTime = new \DateTime('2017-01-10 11:00', new \DateTimeZone('Europe/Berlin'));
248+
249+
$this->assertDateTimeEquals($dateTime, $transformer->reverseTransform('2017-01-10'));
250+
}
251+
243252
public function testReverseTransformWithDifferentPatterns()
244253
{
245254
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'MM*yyyy*dd HH|mm|ss');

0 commit comments

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