Skip to content

Commit 6e102fd

Browse files
committed
Update whereDate
1 parent fdf0248 commit 6e102fd

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ All notable changes to this project will be documented in this file.
1616
- Remove `Query\Builder::whereAll($column, $values)`. Use `Query\Builder::where($column, 'all', $values)` instead. [#16](https://github.com/GromNaN/laravel-mongodb-private/pull/16) by [@GromNaN](https://github.com/GromNaN).
1717
- Fix validation of unique values when the validated value is found as part of an existing value. [#21](https://github.com/GromNaN/laravel-mongodb-private/pull/21) by [@GromNaN](https://github.com/GromNaN).
1818
- Support `%` and `_` in `like` expression [#17](https://github.com/GromNaN/laravel-mongodb-private/pull/17) by [@GromNaN](https://github.com/GromNaN).
19-
- Fix Query on `whereDate`, `whereDay`, `whereMonth`, `whereYear`, `whereTime` to use MongoDB operators [#2376](https://github.com/jenssegers/laravel-mongodb/pull/2376) by [@Davpyu](https://github.com/Davpyu)
19+
- Fix Query on `whereDate`, `whereDay`, `whereMonth`, `whereYear`, `whereTime` to use MongoDB operators [#2376](https://github.com/jenssegers/laravel-mongodb/pull/2572) by [@Davpyu](https://github.com/Davpyu) and [@GromNaN](https://github.com/GromNaN)
2020

2121
## [3.9.2] - 2022-09-01
2222

src/Query/Builder.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,16 +1202,10 @@ protected function compileWhereDate(array $where): array
12021202
],
12031203
],
12041204
'ne' => [
1205-
'$or' => [
1206-
[
1207-
$where['column'] => [
1208-
'$lt' => $startOfDay,
1209-
],
1210-
],
1211-
[
1212-
$where['column'] => [
1213-
'$gt' => $endOfDay,
1214-
],
1205+
$where['column'] => [
1206+
'$not' => [
1207+
'$gte' => $startOfDay,
1208+
'$lte' => $endOfDay,
12151209
],
12161210
],
12171211
],

tests/Query/BuilderTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,11 @@ function (Builder $builder) {
662662
];
663663

664664
yield 'where date !=' => [
665-
['find' => [['$or' => [
666-
['created_at' => ['$lt' => new UTCDateTime(new DateTimeImmutable('2018-09-30 00:00:00.000 +00:00'))]],
667-
['created_at' => ['$gt' => new UTCDateTime(new DateTimeImmutable('2018-09-30 23:59:59.999 +00:00'))]],
665+
['find' => [['created_at' => [
666+
'$not' => [
667+
'$gte' => new UTCDateTime(new DateTimeImmutable('2018-09-30 00:00:00.000 +00:00')),
668+
'$lte' => new UTCDateTime(new DateTimeImmutable('2018-09-30 23:59:59.999 +00:00')),
669+
],
668670
]], []]],
669671
fn (Builder $builder) => $builder->whereDate('created_at', '!=', '2018-09-30'),
670672
];

tests/QueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function testWhereDate(): void
220220
$this->assertCount(2, $birthdayCount);
221221

222222
$birthdayCount = Birthday::whereDate('birthday', '<>', '2021-05-11')->get();
223-
$this->assertCount(5, $birthdayCount);
223+
$this->assertCount(6, $birthdayCount);
224224
}
225225

226226
public function testWhereDay(): void

0 commit comments

Comments
 (0)