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:
Fabien Potencier 2013-04-21 18:08:31 +02:00
commit 9b05da747a
2 changed files with 15 additions and 2 deletions

View File

@ -130,8 +130,12 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
throw new TransformationFailedException(intl_get_error_message());
}
// read timestamp into DateTime object - the formatter delivers in UTC
$dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
try {
// read timestamp into DateTime object - the formatter delivers in UTC
$dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
} catch (\Exception $e) {
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}
if ('UTC' !== $this->inputTimezone) {
try {

View File

@ -263,4 +263,13 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
$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');
}
}