[Form] DateTimeToLocalizedStringTransformer does not use TZ when using only date
This commit is contained in:
parent
e9f2512c04
commit
031d8c2c8b
|
@ -130,11 +130,11 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||
try {
|
||||
if ($dateOnly) {
|
||||
// we only care about year-month-date, which has been delivered as a timestamp pointing to UTC midnight
|
||||
return new \DateTime(gmdate('Y-m-d', $timestamp), new \DateTimeZone($this->inputTimezone));
|
||||
$dateTime = new \DateTime(gmdate('Y-m-d', $timestamp), new \DateTimeZone($this->outputTimezone));
|
||||
} else {
|
||||
// read timestamp into DateTime object - the formatter delivers a timestamp
|
||||
$dateTime = new \DateTime(sprintf('@%s', $timestamp));
|
||||
}
|
||||
|
||||
// read timestamp into DateTime object - the formatter delivers a timestamp
|
||||
$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));
|
||||
|
|
|
@ -240,6 +240,15 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
|||
$this->assertDateTimeEquals($dateTime, $transformer->reverseTransform('03.02.2010, 04:05'));
|
||||
}
|
||||
|
||||
public function testReverseTransformOnlyDateWithDifferentTimezones()
|
||||
{
|
||||
$transformer = new DateTimeToLocalizedStringTransformer('Europe/Berlin', 'Pacific/Tahiti', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd');
|
||||
|
||||
$dateTime = new \DateTime('2017-01-10 11:00', new \DateTimeZone('Europe/Berlin'));
|
||||
|
||||
$this->assertDateTimeEquals($dateTime, $transformer->reverseTransform('2017-01-10'));
|
||||
}
|
||||
|
||||
public function testReverseTransformWithDifferentPatterns()
|
||||
{
|
||||
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'MM*yyyy*dd HH|mm|ss');
|
||||
|
|
Reference in New Issue