Skip to content

Commit 7d0793a

Browse files
committed
relax some date parser patterns
1 parent 789c330 commit 7d0793a

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function format(\DateTime $dateTime, $length)
3333
*/
3434
public function getReverseMatchingRegExp($length)
3535
{
36-
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
36+
return 1 === $length ? '\d{1,2}' : '\d{1,'.$length.'}';
3737
}
3838

3939
/**

src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function getReverseMatchingRegExp($length)
104104
$regExp = '[JFMASOND]';
105105
break;
106106
default:
107-
$regExp = '\d{'.$length.'}';
107+
$regExp = '\d{1,'.$length.'}';
108108
break;
109109
}
110110

src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function format(\DateTime $dateTime, $length)
3737
*/
3838
public function getReverseMatchingRegExp($length)
3939
{
40-
return 2 === $length ? '\d{2}' : '\d{4}';
40+
return 2 === $length ? '\d{2}' : '\d{1,4}';
4141
}
4242

4343
/**

src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ public function parseMonthProvider()
618618
{
619619
return [
620620
['y-M-d', '1970-1-1', 0],
621+
['y-MM-d', '1970-1-1', 0],
621622
['y-MMM-d', '1970-Jan-1', 0],
622623
['y-MMMM-d', '1970-January-1', 0],
623624
];
@@ -636,6 +637,7 @@ public function parseDayProvider()
636637
{
637638
return [
638639
['y-M-d', '1970-1-1', 0],
640+
['y-M-dd', '1970-1-1', 0],
639641
['y-M-dd', '1970-1-01', 0],
640642
['y-M-ddd', '1970-1-001', 0],
641643
];

src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ public function parseQuarterProvider()
183183
return $this->notImplemented(parent::parseQuarterProvider());
184184
}
185185

186+
public function testParseThreeDigitsYears()
187+
{
188+
if (PHP_INT_SIZE < 8) {
189+
$this->markTestSkipped('Parsing three digits years requires a 64bit PHP.');
190+
}
191+
192+
$formatter = $this->getDefaultDateFormatter('yyyy-M-d');
193+
$this->assertSame(-32157648000, $formatter->parse('950-12-19'));
194+
$this->assertIsIntlSuccess($formatter, 'U_ZERO_ERROR', IntlGlobals::U_ZERO_ERROR);
195+
}
196+
186197
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
187198
{
188199
return new IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern);

0 commit comments

Comments
 (0)