diff --git a/src/EDTFUtils.php b/src/EDTFUtils.php index c8bd6c5..3176550 100644 --- a/src/EDTFUtils.php +++ b/src/EDTFUtils.php @@ -216,6 +216,9 @@ public static function validateDate($datetime_str, $strict = FALSE) { elseif (strlen(ltrim($parsed_date[self::YEAR_BASE], '-')) > 4) { $msgs[] = "Years longer than 4 digits must be prefixed with a 'Y'."; } + elseif (strlen($parsed_date[self::YEAR_BASE]) < 4) { + $msgs[] = "Years must be at least 4 characters long."; + } $strict_pattern = 'Y'; // Month. diff --git a/tests/src/Kernel/EdtfUtilsTest.php b/tests/src/Kernel/EdtfUtilsTest.php index 685428e..a868901 100644 --- a/tests/src/Kernel/EdtfUtilsTest.php +++ b/tests/src/Kernel/EdtfUtilsTest.php @@ -37,8 +37,9 @@ class EdtfUtilsTest extends KernelTestBase { '19000' => ['Years longer than 4 digits must be prefixed with a \'Y\'.'], 'Y19000' => [], '190u' => ['Could not parse the date \'190u\'.'], - '190' => [], + '190' => ['Years must be at least 4 characters long.'], '190-99-52' => [ + 'Years must be at least 4 characters long.', 'Provided month value \'99\' is not valid.', 'Provided day value \'52\' is not valid.', ], @@ -79,7 +80,7 @@ public function testIso8601() { '19000' => '', 'Y19000' => '19000', '190u' => '', - '190' => '190', + '190' => '', '190-99-52' => '', '1900-01-02T' => '', '1900-01-02T1:1:1' => '',