Skip to content

Commit 7e4294f

Browse files
committed
Merge pull request #338
2 parents 86daabf + 188c7ec commit 7e4294f

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

php_phongo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ void php_phongo_new_datetime_from_utcdatetime(zval *object, int64_t milliseconds
20852085
datetime_obj = Z_PHPDATE_P(object);
20862086
php_date_initialize(datetime_obj, sec, sec_len, NULL, NULL, 0 TSRMLS_CC);
20872087
efree(sec);
2088-
datetime_obj->time->f = milliseconds % 1000;
2088+
datetime_obj->time->f = (double) (milliseconds % 1000) / 1000;
20892089
} /* }}} */
20902090
void php_phongo_new_timestamp_from_increment_and_timestamp(zval *object, uint32_t increment, uint32_t timestamp TSRMLS_DC) /* {{{ */
20912091
{

tests/bson/bson-utcdatetime-int-size.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object(MongoDB\BSON\UTCDateTime)#%d (1) {
2626
}
2727
object(DateTime)#%d (3) {
2828
["date"]=>
29-
string(29) "2014-11-20 01:03:31.987000000"
29+
string(26) "2014-11-20 01:03:31.987000"
3030
["timezone_type"]=>
3131
int(1)
3232
["timezone"]=>
@@ -39,7 +39,7 @@ object(MongoDB\BSON\UTCDateTime)#%d (1) {
3939
}
4040
object(DateTime)#%d (3) {
4141
["date"]=>
42-
string(29) "2014-11-20 01:03:31.987000000"
42+
string(26) "2014-11-20 01:03:31.987000"
4343
["timezone_type"]=>
4444
int(1)
4545
["timezone"]=>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
BSON BSON\UTCDateTime::toDateTime() dumping seconds and microseconds
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
use MongoDB\BSON as BSON;
8+
9+
require_once __DIR__ . "/../utils/basic.inc";
10+
11+
$utcdatetime = new BSON\UTCDateTime("1416445411987");
12+
$datetime = $utcdatetime->toDateTime();
13+
echo $datetime->format('U.u'), "\n";
14+
15+
?>
16+
===DONE===
17+
<?php exit(0); ?>
18+
--EXPECT--
19+
1416445411.987000
20+
===DONE===

tests/bson/bug0631.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
PHPC-631: UTCDateTime::toDateTime() may return object that cannot be serialized
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$utcdatetime = new MongoDB\BSON\UTCDateTime(1466540755123);
10+
$datetime = $utcdatetime->toDateTime();
11+
$s = serialize($datetime);
12+
13+
var_dump($datetime);
14+
15+
echo "\n", $s, "\n\n";
16+
17+
var_dump(unserialize($s));
18+
19+
?>
20+
===DONE===
21+
<?php exit(0); ?>
22+
--EXPECTF--
23+
object(DateTime)#%d (%d) {
24+
["date"]=>
25+
string(26) "2016-06-21 20:25:55.123000"
26+
["timezone_type"]=>
27+
int(1)
28+
["timezone"]=>
29+
string(6) "+00:00"
30+
}
31+
32+
O:8:"DateTime":3:{s:4:"date";s:26:"2016-06-21 20:25:55.123000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}
33+
34+
object(DateTime)#%d (%d) {
35+
["date"]=>
36+
string(26) "2016-06-21 20:25:55.123000"
37+
["timezone_type"]=>
38+
int(1)
39+
["timezone"]=>
40+
string(6) "+00:00"
41+
}
42+
===DONE===

0 commit comments

Comments
 (0)