Skip to content

Commit b72ca7c

Browse files
committed
merged branch bschussek/issue4242 (PR symfony#4848)
Commits ------- b7aae48 [Locale] Fixed error resetting in StubIntlDateFormatter::parse() Discussion ---------- [Locale] Fixed error resetting in StubIntlDateFormatter::parse() Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: symfony#4242 Todo: - --------------------------------------------------------------------------- by bschussek at 2012-07-11T08:00:15Z ping @eriksencosta, @igorw - is this solved as intended? --------------------------------------------------------------------------- by eriksencosta at 2012-07-11T11:20:24Z Yes, thanks!
2 parents f83401a + b7aae48 commit b72ca7c

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public function parse(\DateTime $dateTime, $value)
151151
}
152152
}
153153

154+
// reset error code and message
155+
StubIntl::setError(StubIntl::U_ZERO_ERROR);
156+
154157
return $this->calculateUnixTimestamp($dateTime, $options);
155158
}
156159

src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,8 @@ public function parse($value, &$position = null)
378378
$timestamp = $transformer->parse($dateTime, $value);
379379

380380
// behave like the intl extension. FullTransformer::parse() set the proper error
381-
if (false === $timestamp) {
382-
$this->errorCode = StubIntl::getErrorCode();
383-
$this->errorMessage = StubIntl::getErrorMessage();
384-
}
381+
$this->errorCode = StubIntl::getErrorCode();
382+
$this->errorMessage = StubIntl::getErrorMessage();
385383

386384
return $timestamp;
387385
}

src/Symfony/Component/Locale/Tests/Stub/StubIntlDateFormatterTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,24 @@ public function parseErrorProvider()
859859
);
860860
}
861861

862+
/*
863+
* https://github.com/symfony/symfony/issues/4242
864+
*/
865+
public function testParseAfterErrorIntl()
866+
{
867+
$this->testParseErrorIntl('y-MMMMM-d', '1970-J-1');
868+
$this->testParseIntl('y-M-d', '1970-1-1', 0);
869+
}
870+
871+
/*
872+
* https://github.com/symfony/symfony/issues/4242
873+
*/
874+
public function testParseAfterErrorStub()
875+
{
876+
$this->testParseErrorStub('y-MMMMM-d', '1970-J-1');
877+
$this->testParseStub('y-M-d', '1970-1-1', 0);
878+
}
879+
862880
/**
863881
* Just to document the differences between the stub and the intl implementations. The intl can parse
864882
* any of the tested formats alone. The stub does not implement them as it would be needed to add more

0 commit comments

Comments
 (0)