Skip to content

Commit

Permalink
[Bugfix] Change DateRangeFilterType to automatically modify the dates…
Browse files Browse the repository at this point in the history
… to fit between given range, regardless of their time
  • Loading branch information
Kreyu committed Apr 25, 2023
1 parent c23f2b7 commit 5cb236b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Bridge/Doctrine/Orm/Filter/Type/DateRangeFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,26 @@ public function apply(ProxyQueryInterface $query, FilterData $data, FilterInterf

$criteria = $query->expr()->andX();

if (null !== $value['from']) {
if (null !== $dateFrom = $value['from']) {
$parameterNameFrom = $parameterName.'_from';

$dateFrom = \DateTime::createFromInterface($dateFrom);
$dateFrom->setTime(0, 0);

$criteria->add($query->expr()->gte($queryPath, ":$parameterNameFrom"));

$query->setParameter($parameterNameFrom, $value['from']);
$query->setParameter($parameterNameFrom, $dateFrom);
}

if (null !== $value['to']) {
if (null !== $valueTo = $value['to']) {
$parameterNameTo = $parameterName.'_to';

$criteria->add($query->expr()->lte($queryPath, ":$parameterNameTo"));
$valueTo = \DateTime::createFromInterface($valueTo)->modify('+1 day');
$valueTo->setTime(0, 0);

$criteria->add($query->expr()->lt($queryPath, ":$parameterNameTo"));

$query->setParameter($parameterNameTo, $value['to']);
$query->setParameter($parameterNameTo, $valueTo);
}

$query->andWhere($criteria);
Expand Down

0 comments on commit 5cb236b

Please sign in to comment.