merged branch jaugustin/fix-DateTimeToLocalizedStringTransformer-7561 (PR #7772)
This PR was merged into the master branch.
Discussion
----------
fix DateTimeToLocalizedStringTransformer issue #7561
this PR fix #7561 issue:
This fix possible issue with new `\DateTime` throwing `Exception` not handled by the transformer.
Commits
-------
6ccbbe9
fix DateTimeToLocalizedStringTransformer issue #7561, add tests
This commit is contained in:
commit
9b05da747a
@ -130,8 +130,12 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
throw new TransformationFailedException(intl_get_error_message());
|
throw new TransformationFailedException(intl_get_error_message());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// read timestamp into DateTime object - the formatter delivers in UTC
|
// read timestamp into DateTime object - the formatter delivers in UTC
|
||||||
$dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
|
$dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
||||||
|
}
|
||||||
|
|
||||||
if ('UTC' !== $this->inputTimezone) {
|
if ('UTC' !== $this->inputTimezone) {
|
||||||
try {
|
try {
|
||||||
|
@ -263,4 +263,13 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
|||||||
|
|
||||||
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('31.04.10 04:05'));
|
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('31.04.10 04:05'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
|
*/
|
||||||
|
public function testReverseTransformOutOfTimestampRange()
|
||||||
|
{
|
||||||
|
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC');
|
||||||
|
$transformer->reverseTransform('1789-07-14');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user