Skip to content

Commit 800c891

Browse files
committed
(+) rollback whereTime since its not possible to begin with on mongodb
1 parent 078c607 commit 800c891

File tree

3 files changed

+13
-42
lines changed

3 files changed

+13
-42
lines changed

src/Query/Builder.php

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,40 +1281,10 @@ protected function compileWhereTime(array $where)
12811281
{
12821282
extract($where);
12831283

1284-
$operator = $operator === '=' ? '$eq' : $this->conversion[$operator];
1285-
1286-
$time = Carbon::parse($value);
1284+
$where['operator'] = $operator;
1285+
$where['value'] = $value;
12871286

1288-
return [
1289-
'$expr' => [
1290-
'$and' => [
1291-
[
1292-
$operator => [
1293-
[
1294-
'$hour' => '$'.$column
1295-
],
1296-
$time->hour
1297-
],
1298-
],
1299-
[
1300-
$operator => [
1301-
[
1302-
'$minute' => '$'.$column
1303-
],
1304-
$time->minute
1305-
],
1306-
],
1307-
[
1308-
$operator => [
1309-
[
1310-
'$second' => '$'.$column
1311-
],
1312-
$time->second
1313-
],
1314-
],
1315-
],
1316-
],
1317-
];
1287+
return $this->compileWhereBasic($where);
13181288
}
13191289

13201290
/**

tests/QueryTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public function setUp(): void
2020
User::create(['name' => 'Tommy Toe', 'age' => 33, 'title' => 'user']);
2121
User::create(['name' => 'Yvonne Yoe', 'age' => 35, 'title' => 'admin']);
2222
User::create(['name' => 'Error', 'age' => null, 'title' => null]);
23-
Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2020-04-10 10:53:11')->toDateTimeString());
24-
Birthday::create(['name' => 'Jane Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:12')->toDateTimeString());
25-
Birthday::create(['name' => 'Harry Hoe', 'birthday' => Carbon::parse('2021-05-11 10:53:13')->toDateTimeString());
26-
Birthday::create(['name' => 'Robert Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:14')->toDateTimeString());
27-
Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:15')->toDateTimeString());
28-
Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:16')->toDateTimeString());
23+
Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2020-04-10 10:53:11')->toDateTimeString(), 'time' => '10:53:11');
24+
Birthday::create(['name' => 'Jane Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:12')->toDateTimeString(), 'time' => '10:53:12');
25+
Birthday::create(['name' => 'Harry Hoe', 'birthday' => Carbon::parse('2021-05-11 10:53:13')->toDateTimeString(), 'time' => '10:53:13');
26+
Birthday::create(['name' => 'Robert Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:14')->toDateTimeString(), 'time' => '10:53:14');
27+
Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:15')->toDateTimeString(), 'time' => '10:53:15');
28+
Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:16')->toDateTimeString(), 'time' => '10:53:16');
2929
}
3030

3131
public function tearDown(): void
@@ -213,10 +213,10 @@ public function testWhereYear(): void
213213

214214
public function testWhereTime(): void
215215
{
216-
$time = Birthday::whereTime('birthday', '10:53:11')->get();
216+
$time = Birthday::whereTime('time', '10:53:11')->get();
217217
$this->assertCount(1, $time);
218218

219-
$time = Birthday::whereTime('birthday', '>=', '10:53:14')->get();
219+
$time = Birthday::whereTime('time', '>=', '10:53:14')->get();
220220
$this->assertCount(3, $time);
221221
}
222222

tests/models/Birthday.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
*
1010
* @property string $name
1111
* @property string $birthday
12+
* @property string $time
1213
*/
1314
class Birthday extends Eloquent
1415
{
1516
protected $connection = 'mongodb';
1617
protected $collection = 'birthday';
17-
protected $fillable = ['name', 'birthday'];
18+
protected $fillable = ['name', 'birthday', 'time'];
1819
}

0 commit comments

Comments
 (0)