Skip to content

Commit 53c4290

Browse files
deividaspetraitisjenssegers
authored andcommitted
Recursive Convert Dates In Where Clause (#914)
* Recursive Convert Dates In Where Clause * Fix StyleCI
1 parent 4e7c4ad commit 53c4290

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,18 @@ protected function compileWheres()
910910
}
911911

912912
// Convert DateTime values to UTCDateTime.
913-
if (isset($where['value']) and $where['value'] instanceof DateTime) {
914-
$where['value'] = new UTCDateTime($where['value']->getTimestamp() * 1000);
913+
if (isset($where['value'])) {
914+
if (is_array($where['value'])) {
915+
array_walk_recursive($where['value'], function (&$item, $key) {
916+
if ($item instanceof DateTime) {
917+
$item = new UTCDateTime($item->getTimestamp() * 1000);
918+
}
919+
});
920+
} else {
921+
if ($where['value'] instanceof DateTime) {
922+
$where['value'] = new UTCDateTime($where['value']->getTimestamp() * 1000);
923+
}
924+
}
915925
}
916926

917927
// The next item in a "chain" of wheres devices the boolean of the

0 commit comments

Comments
 (0)