parent
be2a6d1291
commit
bf6691ca46
@ -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);
|
||||
}
|
||||
|
@ -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');
|
||||
|
Reference in New Issue
Block a user