Skip to content

Commit

Permalink
Vsliv30 3515 creation time filter misbehaviour (#57)
Browse files Browse the repository at this point in the history
* Extended the Equals operator for Date(Time) filtering

* Apply fixes from StyleCI

---------

Co-authored-by: Ngadhnjim Istrefi <ngadhnjim.istrefi@asseco-see.hr>
Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent d3f0752 commit 393d83f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/SearchCallbacks/Equals.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,27 @@ public function execute(Builder $builder, string $column, CategorizedValues $val
}

if ($values->and) {
if ($this->isDate($this->searchParser->type) || $this->isDateTime($this->searchParser->type)) {
if ($this->isDate($this->searchParser->type)) {
foreach ($values->and as $andValue) {
$builder->orWhereDate($column, $andValue);
}
} elseif ($this->isDateTime($this->searchParser->type)) {
foreach ($values->and as $andValue) {
$dateTimeValue = new \DateTime($andValue);
$formattedDateTime = $dateTimeValue->format('Y-m-d H:i:s');

if ($dateTimeValue->format('s') === '00') {
$builder->orWhere(function ($query) use ($column, $formattedDateTime) {
$query->whereDate($column, '=', date('Y-m-d', strtotime($formattedDateTime)))
->whereTime($column, '>=', date('H:i', strtotime($formattedDateTime)))
->whereTime($column, '<', date('H:i', strtotime($formattedDateTime . ' +1 minute')));
});
} else {
$builder->orWhere(function ($query) use ($column, $formattedDateTime) {
$query->where($column, '=', $formattedDateTime);
});
}
}
} else {
$builder->whereIn($column, $values->and);
}
Expand Down

0 comments on commit 393d83f

Please sign in to comment.