Skip to content

Commit 290cbf6

Browse files
committed
Merged pull request #206
2 parents 7924c08 + b67a090 commit 290cbf6

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

src/BSON/UTCDateTime.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,19 @@ PHP_METHOD(UTCDateTime, __construct)
6262
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
6363
intern = Z_UTCDATETIME_OBJ_P(getThis());
6464

65-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &milliseconds) == FAILURE) {
66-
zend_restore_error_handling(&error_handling TSRMLS_CC);
67-
return;
68-
}
6965
#if SIZEOF_LONG == 4
70-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s", &s_milliseconds, &s_milliseconds_len) == FAILURE) {
66+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &s_milliseconds, &s_milliseconds_len) == FAILURE) {
7167
zend_restore_error_handling(&error_handling TSRMLS_CC);
7268
return;
7369
}
7470

7571
intern->milliseconds = STRTOLL(s_milliseconds);
7672
#else
73+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &milliseconds) == FAILURE) {
74+
zend_restore_error_handling(&error_handling TSRMLS_CC);
75+
return;
76+
}
77+
7778
intern->milliseconds = milliseconds;
7879
#endif
7980

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
Test for UTCDateTime and integer parsing
3+
--INI--
4+
date.timezone=UTC
5+
error_reporting=-1
6+
dislay_errors=1
7+
--FILE--
8+
<?php
9+
echo "As number:\n";
10+
$utcdatetime = new MongoDB\BSON\UTCDateTime(1416445411987);
11+
var_dump($utcdatetime);
12+
var_dump($utcdatetime->toDateTime());
13+
14+
echo "As string:\n";
15+
$utcdatetime = new MongoDB\BSON\UTCDateTime('1416445411987');
16+
var_dump($utcdatetime);
17+
var_dump($utcdatetime->toDateTime());
18+
?>
19+
--EXPECTF--
20+
As number:
21+
object(MongoDB\BSON\UTCDateTime)#%d (1) {
22+
["milliseconds"]=>
23+
%r(string\(13\) "|int\()%r1416445411987%r("|\))%r
24+
}
25+
object(DateTime)#%d (3) {
26+
["date"]=>
27+
string(29) "2014-11-20 01:03:31.987000000"
28+
["timezone_type"]=>
29+
int(1)
30+
["timezone"]=>
31+
string(6) "+00:00"
32+
}
33+
As string:
34+
object(MongoDB\BSON\UTCDateTime)#%d (1) {
35+
["milliseconds"]=>
36+
%r(string\(13\) "|int\()%r1416445411987%r("|\))%r
37+
}
38+
object(DateTime)#%d (3) {
39+
["date"]=>
40+
string(29) "2014-11-20 01:03:31.987000000"
41+
["timezone_type"]=>
42+
int(1)
43+
["timezone"]=>
44+
string(6) "+00:00"
45+
}

0 commit comments

Comments
 (0)