From c8cf1aff7d25f022bb5c368d588064b4a6602464 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 23 Jul 2019 14:07:40 +0200 Subject: [PATCH] relax some date parser patterns --- .../Intl/DateFormatter/DateFormat/DayTransformer.php | 2 +- .../Intl/DateFormatter/DateFormat/MonthTransformer.php | 2 +- .../Intl/DateFormatter/DateFormat/YearTransformer.php | 2 +- .../DateFormatter/AbstractIntlDateFormatterTest.php | 9 ++++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php index c07855df1c8de..8e805baff8608 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php @@ -33,7 +33,7 @@ public function format(\DateTime $dateTime, $length) */ public function getReverseMatchingRegExp($length) { - return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}'; + return 1 === $length ? '\d{1,2}' : '\d{1,'.$length.'}'; } /** diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php index 40ab1d67d7290..04be7858c241f 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php @@ -104,7 +104,7 @@ public function getReverseMatchingRegExp($length) $regExp = '[JFMASOND]'; break; default: - $regExp = '\d{'.$length.'}'; + $regExp = '\d{1,'.$length.'}'; break; } diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php index 043e6f321c2f9..a892c664af59d 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php @@ -37,7 +37,7 @@ public function format(\DateTime $dateTime, $length) */ public function getReverseMatchingRegExp($length) { - return 2 === $length ? '\d{2}' : '\d{4}'; + return 2 === $length ? '\d{2}' : '\d{1,4}'; } /** diff --git a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php index a1ade6a42b55e..31cd170a6dc8f 100644 --- a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php @@ -548,8 +548,12 @@ public function testGetTimeType() /** * @dataProvider parseProvider */ - public function testParse($pattern, $value, $expected) + public function testParse($pattern, $value, $expected, $requires64bit = false) { + if ($requires64bit && PHP_INT_SIZE < 8) { + $this->markTestSkipped(sprintf('Parsing "%s" requires a 64bit PHP.', $value)); + } + $errorCode = IntlGlobals::U_ZERO_ERROR; $errorMessage = 'U_ZERO_ERROR'; @@ -588,6 +592,7 @@ public function parseYearProvider() return [ ['y-M-d', '1970-1-1', 0], ['yy-M-d', '70-1-1', 0], + ['yyyy-M-d', '950-12-19', -32157216000], ]; } @@ -618,6 +623,7 @@ public function parseMonthProvider() { return [ ['y-M-d', '1970-1-1', 0], + ['y-MM-d', '1970-1-1', 0], ['y-MMM-d', '1970-Jan-1', 0], ['y-MMMM-d', '1970-January-1', 0], ]; @@ -636,6 +642,7 @@ public function parseDayProvider() { return [ ['y-M-d', '1970-1-1', 0], + ['y-M-dd', '1970-1-1', 0], ['y-M-dd', '1970-1-01', 0], ['y-M-ddd', '1970-1-001', 0], ];