Skip to content

Commit 918d732

Browse files
Merge branch '3.2'
* 3.2: Fix getMock usage Remove dead code [Form] DateTimeToLocalizedStringTransformer does not use TZ when using only date [Validator] Fix caching of constraints derived from non-serializable parents [TwigBundle] Fix bug where namespaced paths don't take parent bundles in account [FrameworkBundle] Fix relative paths used as cache keys respect groups when merging constraints fix IPv6 address handling in server commands
2 parents db657b7 + 99c7065 commit 918d732

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

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

Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ public function testReverseTransformWithDifferentTimezones()
237237
$this->assertDateTimeEquals($dateTime, $transformer->reverseTransform('03.02.2010, 04:05'));
238238
}
239239

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

0 commit comments

Comments
 (0)