Issue was introduced in #19541
This commit is contained in:
Matteo Beccati 2016-09-07 13:06:20 +02:00
parent be2a6d1291
commit bf6691ca46
2 changed files with 21 additions and 1 deletions

View File

@ -134,7 +134,10 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
}
// read timestamp into DateTime object - the formatter delivers a timestamp
$dateTime = new \DateTime(sprintf('@%s', $timestamp), new \DateTimeZone($this->outputTimezone));
$dateTime = new \DateTime(sprintf('@%s', $timestamp));
// set timezone separately, as it would be ignored if set via the constructor,
// see http://php.net/manual/en/datetime.construct.php
$dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
} catch (\Exception $e) {
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}

View File

@ -134,6 +134,23 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
$this->assertEquals($dateTime->format('d.m.Y, H:i'), $transformer->transform($input));
}
public function testReverseTransformWithNoConstructorParameters()
{
$tz = date_default_timezone_get();
date_default_timezone_set('Europe/Rome');
$transformer = new DateTimeToLocalizedStringTransformer();
$dateTime = new \DateTime('2010-02-03 04:05');
$this->assertEquals(
$dateTime->format('c'),
$transformer->reverseTransform('03.02.2010, 04:05')->format('c')
);
date_default_timezone_set($tz);
}
public function testTransformWithDifferentPatterns()
{
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'MM*yyyy*dd HH|mm|ss');