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