From 19201b87f7dba2a7cbf1cccdf0e1da13c04ee9c9 Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 8 Nov 2018 14:33:47 +0100 Subject: [PATCH] Fix #1497 hasFormat more strict with full-year (#1499) * Fix #1497 hasFormat more strict with full-year --- src/Carbon/Carbon.php | 6 +++--- tests/Carbon/IsTest.php | 1 + tests/CarbonPeriod/AliasTest.php | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Carbon/Carbon.php b/src/Carbon/Carbon.php index f62dd45ec1..7f83dbf446 100644 --- a/src/Carbon/Carbon.php +++ b/src/Carbon/Carbon.php @@ -195,7 +195,7 @@ class Carbon extends DateTime implements JsonSerializable 't' => '(2[89]|3[01])', 'L' => '(0|1)', 'o' => '([1-9][0-9]{0,4})', - 'Y' => '([1-9][0-9]{0,4})', + 'Y' => '([1-9]?[0-9]{4})', 'y' => '([0-9]{2})', 'a' => '(am|pm)', 'A' => '(AM|PM)', @@ -217,8 +217,8 @@ class Carbon extends DateTime implements JsonSerializable 'U' => '([0-9]*)', // The formats below are combinations of the above formats. - 'c' => '(([1-9][0-9]{0,4})\-(1[012]|0[1-9])\-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])[\+\-](1[012]|0[0-9]):([0134][05]))', // Y-m-dTH:i:sP - 'r' => '(([a-zA-Z]{3}), ([123][0-9]|[1-9]) ([a-zA-Z]{3}) ([1-9][0-9]{0,4}) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]) [\+\-](1[012]|0[0-9])([0134][05]))', // D, j M Y H:i:s O + 'c' => '(([1-9]?[0-9]{4})\-(1[012]|0[1-9])\-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])[\+\-](1[012]|0[0-9]):([0134][05]))', // Y-m-dTH:i:sP + 'r' => '(([a-zA-Z]{3}), ([123][0-9]|[1-9]) ([a-zA-Z]{3}) ([1-9]?[0-9]{4}) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]) [\+\-](1[012]|0[0-9])([0134][05]))', // D, j M Y H:i:s O ); /** diff --git a/tests/Carbon/IsTest.php b/tests/Carbon/IsTest.php index aaac189c51..691f305535 100644 --- a/tests/Carbon/IsTest.php +++ b/tests/Carbon/IsTest.php @@ -804,5 +804,6 @@ public function testHasFormat() // Regex failure $this->assertFalse(Carbon::hasFormat('1975-5-1', 'Y-m-d')); + $this->assertFalse(Carbon::hasFormat('19-05-01', 'Y-m-d')); } } diff --git a/tests/CarbonPeriod/AliasTest.php b/tests/CarbonPeriod/AliasTest.php index 5fb5a24bd6..2177b6457b 100644 --- a/tests/CarbonPeriod/AliasTest.php +++ b/tests/CarbonPeriod/AliasTest.php @@ -152,6 +152,7 @@ public function testModifyIntervalSingular() public function testChainAliases() { + Carbon::setTestNow('2018-05-15'); $period = CarbonPeriod::days(3)->hours(5)->invert() ->sinceNow()->until(Carbon::now()->subDays(10)) ->options(CarbonPeriod::EXCLUDE_START_DATE)