Skip to content

Commit

Permalink
relax some date parser patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jul 23, 2019
1 parent 789c330 commit 7d0793a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
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
Expand Up @@ -104,7 +104,7 @@ public function getReverseMatchingRegExp($length)
$regExp = '[JFMASOND]';
break;
default:
$regExp = '\d{'.$length.'}';
$regExp = '\d{1,'.$length.'}';
break;
}

Expand Down
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
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
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 comments on commit 7d0793a

Please sign in to comment.