Skip to content

Commit 3a8f90b

Browse files
committed
PHPC-2443: Accept Int64 instances in UTCDateTime constructor
1 parent d0d718e commit 3a8f90b

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/BSON/UTCDateTime.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __construct)
183183
case IS_OBJECT:
184184
if (instanceof_function(Z_OBJCE_P(milliseconds), php_date_get_interface_ce())) {
185185
php_phongo_utcdatetime_init_from_date(intern, Z_PHPDATE_P(milliseconds));
186+
} else if (instanceof_function(Z_OBJCE_P(milliseconds), php_phongo_int64_ce)) {
187+
php_phongo_utcdatetime_init(intern, Z_INT64_OBJ_P(milliseconds)->integer);
186188
} else {
187-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected instance of DateTimeInterface, %s given", ZSTR_VAL(Z_OBJCE_P(milliseconds)->name));
189+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected instance of %s or %s, %s given", ZSTR_VAL(php_date_get_interface_ce()->name), ZSTR_VAL(php_phongo_int64_ce->name), ZSTR_VAL(Z_OBJCE_P(milliseconds)->name));
188190
}
189191
return;
190192

src/BSON/UTCDateTime.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
final class UTCDateTime implements UTCDateTimeInterface, \JsonSerializable, Type, \Serializable
1111
{
1212
#if PHP_VERSION_ID >= 80000
13-
final public function __construct(int|string|float|\DateTimeInterface|null $milliseconds = null) {}
13+
final public function __construct(int|string|float|\DateTimeInterface|Int64|null $milliseconds = null) {}
1414
#else
15-
/** @param int|string|float|\DateTimeInterface|null $milliseconds */
15+
/** @param int|string|float|\DateTimeInterface|Int64|null $milliseconds */
1616
final public function __construct($milliseconds = null) {}
1717
#endif
1818

src/BSON/UTCDateTime_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/bson/bson-utcdatetime-009.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
MongoDB\BSON\UTCDateTime construction from Int64 object
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/basic.inc';
7+
8+
$utcdatetime = new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1416445411987'));
9+
10+
var_dump($utcdatetime);
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECTF--
16+
object(MongoDB\BSON\UTCDateTime)#%d (%d) {
17+
["milliseconds"]=>
18+
string(13) "1416445411987"
19+
}
20+
===DONE===

0 commit comments

Comments
 (0)