Skip to content

UTCDateTime conversion now includes milliseconds #1534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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