From 3c07787af8136a72646fc81495373ff6eabef1aa Mon Sep 17 00:00:00 2001 From: Diego Avola Date: Tue, 18 Jan 2022 20:52:13 -0300 Subject: [PATCH] Time aware fix --- src/behaviors/EntryQueryBehavior.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/behaviors/EntryQueryBehavior.php b/src/behaviors/EntryQueryBehavior.php index 971a8a1..276e247 100644 --- a/src/behaviors/EntryQueryBehavior.php +++ b/src/behaviors/EntryQueryBehavior.php @@ -80,12 +80,14 @@ public function onAfterPrepare() } } + $now = (new \DateTime('now'))->format(\DateTime::ATOM); + if (Craft::$app->db->getIsPgsql()) { if ($this->field && $this->isFuture) { $this->owner->subQuery ->andWhere(Db::parseDateParam( '"field_'. $this->handle .$this->columnSuffix . '"::json->>\'start\'', - date('Y-m-d'), + $now, $this->includeToday ? '>=' : '>' )); } @@ -93,7 +95,7 @@ public function onAfterPrepare() $this->owner->subQuery ->andWhere(Db::parseDateParam( '"field_'. $this->handle .$this->columnSuffix . '"::json->>\'end\'', - date('Y-m-d'), + $now, $this->includeToday ? '<=' : '<' )); } @@ -101,13 +103,13 @@ public function onAfterPrepare() $this->owner->subQuery ->andWhere(Db::parseDateParam( '"field_'. $this->handle .$this->columnSuffix . '"::json->>\'start\'', - date('Y-m-d'), + $now, $this->includeToday ? '<=' : '<' )); $this->owner->subQuery ->andWhere(Db::parseDateParam( '"field_'. $this->handle .$this->columnSuffix . '"::json->>\'end\'', - date('Y-m-d'), + $now, $this->includeToday ? '>=' : '>' )); } @@ -116,7 +118,7 @@ public function onAfterPrepare() $this->owner->subQuery ->andWhere(Db::parseDateParam( "JSON_EXTRACT(field_$this->handle$this->columnSuffix, '$.start')", - date('Y-m-d'), + $now, $this->includeToday ? '>=' : '>' )); } @@ -125,7 +127,7 @@ public function onAfterPrepare() $this->owner->subQuery ->andWhere(Db::parseDateParam( "JSON_EXTRACT(field_$this->handle$this->columnSuffix, '$.end')", - date('Y-m-d'), + $now, $this->includeToday ? '<=' : '<' )); } @@ -134,16 +136,16 @@ public function onAfterPrepare() $this->owner->subQuery ->andWhere(Db::parseDateParam( "JSON_EXTRACT(field_$this->handle$this->columnSuffix, '$.start')", - date('Y-m-d'), + $now, $this->includeToday ? '<=' : '<' )); $this->owner->subQuery ->andWhere(Db::parseDateParam( "JSON_EXTRACT(field_$this->handle$this->columnSuffix, '$.end')", - date('Y-m-d'), + $now, $this->includeToday ? '>=' : '>' )); } } } -} +} \ No newline at end of file