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 ebb43de
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 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 @@ -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';

Expand Down Expand Up @@ -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', -32157648000, true],
];
}

Expand Down Expand Up @@ -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],
];
Expand All @@ -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],
];
Expand Down

0 comments on commit ebb43de

Please sign in to comment.