From b7aae48a744715fffd57cc1a35f8d54eccd3a639 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Wed, 11 Jul 2012 09:53:08 +0200 Subject: [PATCH] [Locale] Fixed error resetting in StubIntlDateFormatter::parse() --- .../Locale/Stub/DateFormat/FullTransformer.php | 3 +++ .../Locale/Stub/StubIntlDateFormatter.php | 6 ++---- .../Tests/Stub/StubIntlDateFormatterTest.php | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php b/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php index 7d64464a76..6c883c99c4 100644 --- a/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php +++ b/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php @@ -151,6 +151,9 @@ class FullTransformer } } + // reset error code and message + StubIntl::setError(StubIntl::U_ZERO_ERROR); + return $this->calculateUnixTimestamp($dateTime, $options); } diff --git a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php index 2dc79d9d5f..7c9cc71e43 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php @@ -378,10 +378,8 @@ class StubIntlDateFormatter $timestamp = $transformer->parse($dateTime, $value); // behave like the intl extension. FullTransformer::parse() set the proper error - if (false === $timestamp) { - $this->errorCode = StubIntl::getErrorCode(); - $this->errorMessage = StubIntl::getErrorMessage(); - } + $this->errorCode = StubIntl::getErrorCode(); + $this->errorMessage = StubIntl::getErrorMessage(); return $timestamp; } diff --git a/src/Symfony/Component/Locale/Tests/Stub/StubIntlDateFormatterTest.php b/src/Symfony/Component/Locale/Tests/Stub/StubIntlDateFormatterTest.php index 994f03fb86..2b3dd832c9 100644 --- a/src/Symfony/Component/Locale/Tests/Stub/StubIntlDateFormatterTest.php +++ b/src/Symfony/Component/Locale/Tests/Stub/StubIntlDateFormatterTest.php @@ -859,6 +859,24 @@ class StubIntlDateFormatterTest extends LocaleTestCase ); } + /* + * https://github.com/symfony/symfony/issues/4242 + */ + public function testParseAfterErrorIntl() + { + $this->testParseErrorIntl('y-MMMMM-d', '1970-J-1'); + $this->testParseIntl('y-M-d', '1970-1-1', 0); + } + + /* + * https://github.com/symfony/symfony/issues/4242 + */ + public function testParseAfterErrorStub() + { + $this->testParseErrorStub('y-MMMMM-d', '1970-J-1'); + $this->testParseStub('y-M-d', '1970-1-1', 0); + } + /** * Just to document the differences between the stub and the intl implementations. The intl can parse * any of the tested formats alone. The stub does not implement them as it would be needed to add more