bug #19879 [Form] Incorrect timezone with DateTimeLocalizedStringTransformer (mbeccati)
This PR was merged into the 2.7 branch.
Discussion
----------
[Form] Incorrect timezone with DateTimeLocalizedStringTransformer
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #19721
| License | MIT
| Doc PR | n.a.
Issue was introduced in #19541
Commits
-------
bf6691c
Fix #19721
This commit is contained in:
commit
d89319218d
@ -134,7 +134,10 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read timestamp into DateTime object - the formatter delivers a timestamp
|
// 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) {
|
} catch (\Exception $e) {
|
||||||
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,23 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
|||||||
$this->assertEquals($dateTime->format('d.m.Y, H:i'), $transformer->transform($input));
|
$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()
|
public function testTransformWithDifferentPatterns()
|
||||||
{
|
{
|
||||||
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'MM*yyyy*dd HH|mm|ss');
|
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'MM*yyyy*dd HH|mm|ss');
|
||||||
|
Reference in New Issue
Block a user