File tree 2 files changed +15
-1
lines changed
src/Jenssegers/Mongodb/Eloquent
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,13 @@ protected function asDateTime($value)
99
99
{
100
100
// Convert UTCDateTime instances.
101
101
if ($ value instanceof UTCDateTime) {
102
- return Date::createFromTimestampMs ($ value ->toDateTime ()->format ('Uv ' ));
102
+ $ date = $ value ->toDateTime ();
103
+
104
+ $ seconds = $ date ->format ('U ' );
105
+ $ milliseconds = abs ($ date ->format ('v ' ));
106
+ $ timestampMs = sprintf ('%d%03d ' , $ seconds , $ milliseconds );
107
+
108
+ return Date::createFromTimestampMs ($ timestampMs );
103
109
}
104
110
105
111
return parent ::asDateTime ($ value );
Original file line number Diff line number Diff line change @@ -425,6 +425,14 @@ public function testDates(): void
425
425
$ user = User::create (['name ' => 'Jane Doe ' , 'birthday ' => '2005-08-08 ' ]);
426
426
$ this ->assertInstanceOf (Carbon::class, $ user ->birthday );
427
427
428
+ // test millisecond-precision dates after 1970:
429
+ $ user = User::create (['name ' => 'Jane Doe ' , 'birthday ' => new DateTime ('2010-08-08 04.08.37.324 ' )]);
430
+ $ this ->assertInstanceOf (Carbon::class, $ user ->birthday );
431
+
432
+ // test millisecond-precision dates before 1970:
433
+ $ user = User::create (['name ' => 'Jane Doe ' , 'birthday ' => new DateTime ('1965-08-08 04.08.37.324 ' )]);
434
+ $ this ->assertInstanceOf (Carbon::class, $ user ->birthday );
435
+
428
436
$ user = User::create (['name ' => 'Jane Doe ' , 'entry ' => ['date ' => '2005-08-08 ' ]]);
429
437
$ this ->assertInstanceOf (Carbon::class, $ user ->getAttribute ('entry.date ' ));
430
438
You can’t perform that action at this time.
0 commit comments