This repository was archived by the owner on Dec 23, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -1471,8 +1471,13 @@ public function serialize() : string
1471
1471
1472
1472
public function jsonSerialize () : mixed
1473
1473
{
1474
+ $seconds = (int ) ( $this -> milliseconds / 1000 );
1475
+ $millis = (int ) ( $this -> milliseconds % 1000 );
1476
+
1477
+ $d = date_create ( " @" . (string ) $seconds );
1478
+
1474
1479
return [
1475
- ' $date' => ( int ) $this -> milliseconds
1480
+ ' $date' => sprintf ( " %s.%03d+0000 " , $d -> format( ' Y-m-d\TH:i:s ' ), $millis )
1476
1481
];
1477
1482
}
1478
1483
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ JsonSerializable: UTCDateTime
3
3
--FILE--
4
4
<?php
5
5
$ doc = [
6
- 'foo ' => new MongoDB \BSON \UTCDateTime ( new \DateTime ( '2016-10-11 13:34:26 UTC ' ) )
6
+ 'foo ' => new MongoDB \BSON \UTCDateTime ( new \DateTime ( '2016-10-11 13:34:26.817 UTC ' ) )
7
7
];
8
8
9
9
echo MongoDB \BSON \toJSON ( \MongoDB \BSON \fromPHP ( $ doc ) ), "\n" ;
@@ -13,12 +13,12 @@ echo $d, "\n";
13
13
var_dump ( \MongoDB \BSON \toPHP ( \MongoDB \BSON \fromJSON ( $ d ) ) );
14
14
?>
15
15
--EXPECTF--
16
- { "foo" : { "$date" : 1476192866000 } }
17
- {"foo":{"$date":1476192866000 }}
16
+ { "foo" : { "$date" : 1476192866817 } }
17
+ {"foo":{"$date":"2016-10-11T13:34:26.817+0000" }}
18
18
object(stdClass)#%d (%d) {
19
19
["foo"]=>
20
20
object(MongoDB\BSON\UTCDateTime)#%d (%d) {
21
21
["milliseconds"]=>
22
- string(13) "1476192866000 "
22
+ string(13) "1476192866817 "
23
23
}
24
24
}
You can’t perform that action at this time.
0 commit comments