From 25cc12c226a1a4456bced379886393bbd67b0274 Mon Sep 17 00:00:00 2001 From: Kareem Montaser <102875573+karemont@users.noreply.github.com> Date: Fri, 23 Jun 2023 18:58:30 +0300 Subject: [PATCH] Allowing Dates in Range This allows a Date to be compared by range without the need to convert it to Unix timestamp (Numeric value). --- src/Domain/Syntax/Range.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Domain/Syntax/Range.php b/src/Domain/Syntax/Range.php index c755b86c..e7992219 100644 --- a/src/Domain/Syntax/Range.php +++ b/src/Domain/Syntax/Range.php @@ -16,11 +16,14 @@ class Range implements SyntaxInterface private ?float $boost; - public function __construct(string $field, array $definitions, ?float $boost = 1.0) + private ?bool $date; + + public function __construct(string $field, array $definitions, ?float $boost = 1.0, ?bool $date = false) { $this->field = $field; $this->definitions = $definitions; $this->boost = $boost; + $this->date = $date; $this->validateDefinitions($definitions); } @@ -36,7 +39,10 @@ private function validateDefinitions(array $definitions): void foreach ($definitions as $key => $value) { Assert::inArray($key, self::RELATIONS); Assert::notNull($value); - Assert::numeric($value); + + if (!$this->date) { + Assert::numeric($value); + } } } }