Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Jenssegers/Mongodb/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function fromDateTime($value)
$value = parent::asDateTime($value);
}

return new UTCDateTime($value->getTimestamp() * 1000);
return new UTCDateTime($value->format('Uv'));
}

/**
Expand All @@ -94,7 +94,7 @@ protected function asDateTime($value)
{
// Convert UTCDateTime instances.
if ($value instanceof UTCDateTime) {
return Carbon::createFromTimestamp($value->toDateTime()->getTimestamp());
return Carbon::createFromTimestampMs($value->toDateTime()->format('Uv'));
}

return parent::asDateTime($value);
Expand All @@ -113,7 +113,7 @@ public function getDateFormat()
*/
public function freshTimestamp()
{
return new UTCDateTime(time() * 1000);
return new UTCDateTime(microtime(true) * 1000);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Jenssegers/Mongodb/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,18 +924,18 @@ protected function compileWheres()
if (is_array($where['value'])) {
array_walk_recursive($where['value'], function (&$item, $key) {
if ($item instanceof DateTime) {
$item = new UTCDateTime($item->getTimestamp() * 1000);
$item = new UTCDateTime($item->format('Uv'));
}
});
} else {
if ($where['value'] instanceof DateTime) {
$where['value'] = new UTCDateTime($where['value']->getTimestamp() * 1000);
$where['value'] = new UTCDateTime($where['value']->format('Uv'));
}
}
} elseif (isset($where['values'])) {
array_walk_recursive($where['values'], function (&$item, $key) {
if ($item instanceof DateTime) {
$item = new UTCDateTime($item->getTimestamp() * 1000);
$item = new UTCDateTime($item->format('Uv'));
}
});
}
Expand Down