@@ -104,6 +104,35 @@ static bool php_phongo_utcdatetime_init_from_date(php_phongo_utcdatetime_t* inte
104
104
return true;
105
105
}
106
106
107
+ static bool php_phongo_utcdatetime_init_from_object (php_phongo_utcdatetime_t * intern , zend_object * object )
108
+ {
109
+ if (instanceof_function (object -> ce , php_date_get_interface_ce ())) {
110
+ php_phongo_utcdatetime_init_from_date (intern , php_date_obj_from_obj (object ));
111
+
112
+ return true;
113
+ }
114
+
115
+ if (instanceof_function (object -> ce , php_phongo_int64_ce )) {
116
+ php_phongo_utcdatetime_init (intern , php_int64_fetch_object (object )-> integer );
117
+
118
+ return true;
119
+ }
120
+
121
+ 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 (object -> ce -> name ));
122
+
123
+ return false;
124
+ }
125
+
126
+ static bool php_phongo_utcdatetime_init_from_double (php_phongo_utcdatetime_t * intern , double milliseconds )
127
+ {
128
+ char tmp [24 ];
129
+ int tmp_len ;
130
+
131
+ tmp_len = snprintf (tmp , sizeof (tmp ), "%.0f" , milliseconds > 0 ? floor (milliseconds ) : ceil (milliseconds ));
132
+
133
+ return php_phongo_utcdatetime_init_from_string (intern , tmp , tmp_len );
134
+ }
135
+
107
136
static HashTable * php_phongo_utcdatetime_get_properties_hash (phongo_compat_object_handler_type * object , bool is_temp )
108
137
{
109
138
php_phongo_utcdatetime_t * intern ;
@@ -181,28 +210,15 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __construct)
181
210
182
211
switch (Z_TYPE_P (milliseconds )) {
183
212
case IS_OBJECT :
184
- if (instanceof_function (Z_OBJCE_P (milliseconds ), php_date_get_interface_ce ())) {
185
- 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 );
188
- } else {
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 ));
190
- }
213
+ php_phongo_utcdatetime_init_from_object (intern , Z_OBJ_P (milliseconds ));
191
214
return ;
192
215
193
216
case IS_LONG :
194
217
php_phongo_utcdatetime_init (intern , Z_LVAL_P (milliseconds ));
195
218
return ;
196
219
197
- case IS_DOUBLE : {
198
- char tmp [24 ];
199
- int tmp_len ;
200
-
201
- tmp_len = snprintf (tmp , sizeof (tmp ), "%.0f" , Z_DVAL_P (milliseconds ) > 0 ? floor (Z_DVAL_P (milliseconds )) : ceil (Z_DVAL_P (milliseconds )));
202
-
203
- php_phongo_utcdatetime_init_from_string (intern , tmp , tmp_len );
204
- }
205
-
220
+ case IS_DOUBLE :
221
+ php_phongo_utcdatetime_init_from_double (intern , Z_DVAL_P (milliseconds ));
206
222
return ;
207
223
208
224
case IS_STRING :
0 commit comments