@@ -1200,6 +1200,86 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time)
1200
1200
}
1201
1201
}
1202
1202
1203
+ U_CFUNC PHP_FUNCTION (intlcal_to_date_time)
1204
+ {
1205
+ zval *retval = NULL ;
1206
+ CALENDAR_METHOD_INIT_VARS;
1207
+
1208
+ if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC, getThis (), " O" ,
1209
+ &object, Calendar_ce_ptr) == FAILURE) {
1210
+ intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
1211
+ " intlcal_to_date_time: bad arguments" , 0 TSRMLS_CC);
1212
+ RETURN_FALSE;
1213
+ }
1214
+
1215
+ CALENDAR_METHOD_FETCH_OBJECT;
1216
+
1217
+ /* There are no exported functions in ext/date to this
1218
+ * in a more native fashion */
1219
+ double date = co->ucal ->getTime (CALENDAR_ERROR_CODE (co)) / 1000 .;
1220
+ int64_t ts;
1221
+ char ts_str[sizeof (" @-9223372036854775808" )];
1222
+ int ts_str_len;
1223
+ zval ts_zval = zval_used_for_init;
1224
+
1225
+ INTL_METHOD_CHECK_STATUS (co, " Call to ICU method has failed" );
1226
+
1227
+ if (date > (double )U_INT64_MAX || date < (double )U_INT64_MIN) {
1228
+ intl_errors_set (CALENDAR_ERROR_P (co), U_ILLEGAL_ARGUMENT_ERROR,
1229
+ " intlcal_to_date_time: The calendar date is out of the "
1230
+ " range for a 64-bit integer" , 0 TSRMLS_CC);
1231
+ RETURN_FALSE;
1232
+ }
1233
+
1234
+ ts = (int64_t )date;
1235
+
1236
+ ts_str_len = slprintf (ts_str, sizeof (ts_str), " @%I64d" , ts);
1237
+ ZVAL_STRINGL (&ts_zval, ts_str, ts_str_len, 0 );
1238
+
1239
+ /* Now get the time zone */
1240
+ const TimeZone& tz = co->ucal ->getTimeZone ();
1241
+ zval *timezone_zval = timezone_convert_to_datetimezone (
1242
+ &tz, CALENDAR_ERROR_P (co), " intlcal_to_date_time" TSRMLS_CC);
1243
+ if (timezone_zval == NULL ) {
1244
+ RETURN_FALSE;
1245
+ }
1246
+
1247
+ /* resources allocated from now on */
1248
+
1249
+ /* Finally, instantiate object and call constructor */
1250
+ object_init_ex (return_value, php_date_get_date_ce ());
1251
+ zend_call_method_with_2_params (&return_value, NULL , NULL , " __construct" ,
1252
+ NULL , &ts_zval, timezone_zval);
1253
+ if (EG (exception )) {
1254
+ intl_errors_set (CALENDAR_ERROR_P (co), U_ILLEGAL_ARGUMENT_ERROR,
1255
+ " intlcal_to_date_time: DateTime constructor has thrown exception" ,
1256
+ 1 TSRMLS_CC);
1257
+ zend_object_store_ctor_failed (return_value TSRMLS_CC);
1258
+ zval_ptr_dtor (&return_value);
1259
+
1260
+ RETVAL_FALSE;
1261
+ goto error;
1262
+ }
1263
+
1264
+ /* due to bug #40743, we have to set the time zone again */
1265
+ zend_call_method_with_1_params (&return_value, NULL , NULL , " settimezone" ,
1266
+ &retval, timezone_zval);
1267
+ if (retval == NULL || Z_TYPE_P (retval) == IS_BOOL) {
1268
+ intl_errors_set (CALENDAR_ERROR_P (co), U_ILLEGAL_ARGUMENT_ERROR,
1269
+ " intlcal_to_date_time: call to DateTime::setTimeZone has failed" ,
1270
+ 1 TSRMLS_CC);
1271
+ zval_ptr_dtor (&return_value);
1272
+ RETVAL_FALSE;
1273
+ goto error;
1274
+ }
1275
+
1276
+ error:
1277
+ zval_ptr_dtor (&timezone_zval);
1278
+ if (retval != NULL ) {
1279
+ zval_ptr_dtor (&retval);
1280
+ }
1281
+ }
1282
+
1203
1283
U_CFUNC PHP_FUNCTION (intlcal_get_error_code)
1204
1284
{
1205
1285
CALENDAR_METHOD_INIT_VARS;
0 commit comments