From ad8c7422a07f5a25b697b8c6ed17ed09489762bb Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 30 May 2024 15:14:38 +0300 Subject: [PATCH 1/2] fix datetime --- src/Database/Validator/Datetime.php | 6 ++++++ tests/e2e/Adapter/Base.php | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Database/Validator/Datetime.php b/src/Database/Validator/Datetime.php index 69b3ad010..414435450 100644 --- a/src/Database/Validator/Datetime.php +++ b/src/Database/Validator/Datetime.php @@ -57,6 +57,12 @@ public function isValid($value): bool return false; } + [$year] = explode('-', $value); + + if ((int)$year > 9999 || (int)$year < 1000) { + return false; + } + return true; } diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index 7ba6cd297..87c461f78 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -5730,7 +5730,17 @@ public function testCreateDatetime(): void $this->assertInstanceOf(StructureException::class, $e); } + try { + static::getDatabase()->createDocument('datetime', new Document([ + 'date' => '+055769-02-14T17:56:18.000Z' + ])); + $this->fail('Failed to throw exception'); + } catch (Exception $e) { + $this->assertInstanceOf(StructureException::class, $e); + } + $invalidDates = [ + '+055769-02-14T17:56:18.000Z1', '1975-12-06 00:00:61', '16/01/2024 12:00:00AM' ]; From 4f7dbfe38e5cd77b87963fe5bde3fcd70eea0d29 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 30 May 2024 15:28:16 +0300 Subject: [PATCH 2/2] fix year --- src/Database/Validator/Datetime.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Validator/Datetime.php b/src/Database/Validator/Datetime.php index 414435450..7f8f8ff35 100644 --- a/src/Database/Validator/Datetime.php +++ b/src/Database/Validator/Datetime.php @@ -59,7 +59,7 @@ public function isValid($value): bool [$year] = explode('-', $value); - if ((int)$year > 9999 || (int)$year < 1000) { + if ((int)$year > 9999) { return false; }