Skip to content

Commit 078c607

Browse files
committed
(+) use new logic for whereDate
1 parent e2c3023 commit 078c607

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

src/Query/Builder.php

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,42 +1164,45 @@ protected function compileWhereDate(array $where)
11641164
{
11651165
extract($where);
11661166

1167-
$date = Carbon::parse($value);
1167+
$startOfDay = new UTCDateTime(Carbon::parse($value)->startOfDay());
1168+
$endOfDay = new UTCDateTime(Carbon::parse($value)->endOfDay());
11681169

11691170
$operator = $this->conversion[$operator];
1170-
$operatorDay = $operator === '=' ? '$eq' : $operator;
1171-
$operatorMonthYear = $operator === '=' ? '$eq' : (in_array($operator, ['$gt', '$lt']) ? $operator . 'e' : $operator);
11721171

1173-
return [
1174-
'$expr' => [
1175-
'$and' => [
1176-
[
1177-
$operatorDay => [
1178-
[
1179-
'$dayOfMonth' => '$'.$column
1180-
],
1181-
$date->day
1182-
],
1183-
],
1184-
[
1185-
$operatorMonthYear => [
1186-
[
1187-
'$month' => '$'.$column
1188-
],
1189-
$date->month
1190-
],
1191-
],
1192-
[
1193-
$operatorMonthYear => [
1194-
[
1195-
'$year' => '$'.$column
1196-
],
1197-
$date->year
1198-
],
1199-
],
1172+
return match($operator) {
1173+
'=' => [
1174+
$column => [
1175+
'$gte' => $startOfDay,
1176+
'$lte' => $endOfDay,
12001177
],
12011178
],
1202-
];
1179+
'$ne' => [
1180+
$column => [
1181+
'$gt' => $endOfDay,
1182+
'$lt' => $startOfDay,
1183+
],
1184+
],
1185+
'$lt' => [
1186+
$column => [
1187+
'$lt' => $startOfDay,
1188+
],
1189+
],
1190+
'$gt' => [
1191+
$column => [
1192+
'$gt' => $endOfDay,
1193+
],
1194+
],
1195+
'$lte' => [
1196+
$column => [
1197+
'$lte' => $endOfDay,
1198+
],
1199+
],
1200+
'$gte' => [
1201+
$column => [
1202+
'$gte' => $startOfDay,
1203+
],
1204+
],
1205+
};
12031206
}
12041207

12051208
/**

0 commit comments

Comments
 (0)