Skip to content

Commit 36dc1a8

Browse files
committed
Clean up asDateTime method on model
This will not change how it functions, just makes it simpler
1 parent 4d12cba commit 36dc1a8

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/Eloquent/Model.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use MongoDB\BSON\UTCDateTime;
2626
use MongoDB\Laravel\Query\Builder as QueryBuilder;
2727

28-
use function abs;
2928
use function array_key_exists;
3029
use function array_keys;
3130
use function array_merge;
@@ -41,7 +40,6 @@
4140
use function is_string;
4241
use function ltrim;
4342
use function method_exists;
44-
use function sprintf;
4543
use function str_contains;
4644
use function str_starts_with;
4745
use function strcmp;
@@ -139,15 +137,9 @@ public function fromDateTime($value)
139137
/** @inheritdoc */
140138
protected function asDateTime($value)
141139
{
142-
// Convert UTCDateTime instances.
140+
// Convert UTCDateTime instances to Carbon.
143141
if ($value instanceof UTCDateTime) {
144-
$date = $value->toDateTime();
145-
146-
$seconds = $date->format('U');
147-
$milliseconds = abs((int) $date->format('v'));
148-
$timestampMs = sprintf('%d%03d', $seconds, $milliseconds);
149-
150-
return Date::createFromTimestampMs($timestampMs);
142+
return Date::instance($value->toDateTime());
151143
}
152144

153145
return parent::asDateTime($value);

0 commit comments

Comments
 (0)