Skip to content

Commit 393d83f

Browse files
Vsliv30 3515 creation time filter misbehaviour (#57)
* Extended the Equals operator for Date(Time) filtering * Apply fixes from StyleCI --------- Co-authored-by: Ngadhnjim Istrefi <[email protected]> Co-authored-by: StyleCI Bot <[email protected]>
1 parent d3f0752 commit 393d83f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/SearchCallbacks/Equals.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,27 @@ public function execute(Builder $builder, string $column, CategorizedValues $val
4242
}
4343

4444
if ($values->and) {
45-
if ($this->isDate($this->searchParser->type) || $this->isDateTime($this->searchParser->type)) {
45+
if ($this->isDate($this->searchParser->type)) {
4646
foreach ($values->and as $andValue) {
4747
$builder->orWhereDate($column, $andValue);
4848
}
49+
} elseif ($this->isDateTime($this->searchParser->type)) {
50+
foreach ($values->and as $andValue) {
51+
$dateTimeValue = new \DateTime($andValue);
52+
$formattedDateTime = $dateTimeValue->format('Y-m-d H:i:s');
53+
54+
if ($dateTimeValue->format('s') === '00') {
55+
$builder->orWhere(function ($query) use ($column, $formattedDateTime) {
56+
$query->whereDate($column, '=', date('Y-m-d', strtotime($formattedDateTime)))
57+
->whereTime($column, '>=', date('H:i', strtotime($formattedDateTime)))
58+
->whereTime($column, '<', date('H:i', strtotime($formattedDateTime . ' +1 minute')));
59+
});
60+
} else {
61+
$builder->orWhere(function ($query) use ($column, $formattedDateTime) {
62+
$query->where($column, '=', $formattedDateTime);
63+
});
64+
}
65+
}
4966
} else {
5067
$builder->whereIn($column, $values->and);
5168
}

0 commit comments

Comments
 (0)