8000 [Intl] relax some date parser patterns by xabbuh · Pull Request #32679 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Intl] relax some date parser patterns #32679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.'}';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getReverseMatchingRegExp($length)
$regExp = '[JFMASOND]';
break;
default:
$regExp = '\d{'.$length.'}';
$regExp = '\d{1,'.$length.'}';
break;
}

Expand Down
8000
Original file line number Diff line number Diff line change
Expand Up @@ -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}';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,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],
];
Expand All @@ -636,6 +637,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],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ public function parseQuarterProvider()
return $this->notImplemented(parent::parseQuarterProvider());
}

public function testParseThreeDigitsYears()
{
if (PHP_INT_SIZE < 8) {
$this->markTestSkipped('Parsing three digits years requires a 64bit PHP.');
}

$formatter = $this->getDefaultDateFormatter('yyyy-M-d');
$this->assertSame(-32157648000, $formatter->parse('950-12-19'));
$this->assertIsIntlSuccess($formatter, 'U_ZERO_ERROR', IntlGlobals::U_ZERO_ERROR);
}

protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
{
return new IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern);
Expand Down
0