U_CFUNC PHP_FUNCTION(intltz_from_date_time_zone) { zval *zv_timezone; TimeZone *tz; php_timezone_obj *tzobj; intl_error_reset(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zv_timezone, php_date_get_timezone_ce()) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_from_date_time_zone: bad arguments", 0); RETURN_NULL(); } tzobj = Z_PHPTIMEZONE_P(zv_timezone); if (!tzobj->initialized) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_from_date_time_zone: DateTimeZone object is unconstructed", 0); RETURN_NULL(); } tz = timezone_convert_datetimezone(tzobj->type, tzobj, FALSE, NULL, "intltz_from_date_time_zone"); if (tz == NULL) { RETURN_NULL(); } timezone_object_construct(tz, return_value, 1); }
U_CFUNC PHP_FUNCTION(intlcal_from_date_time) { zval *zv_arg, zv_tmp, *zv_datetime = NULL, zv_timestamp; php_date_obj *datetime; char *locale_str = NULL; int locale_str_len; TimeZone *timeZone; UErrorCode status = U_ZERO_ERROR; Calendar *cal; intl_error_reset(NULL TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s!", &zv_arg, &locale_str, &locale_str_len) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: bad arguments", 0 TSRMLS_CC); RETURN_NULL(); } if (!(Z_TYPE_P(zv_arg) == IS_OBJECT && instanceof_function( Z_OBJCE_P(zv_arg), php_date_get_date_ce() TSRMLS_CC))) { object_init_ex(&zv_tmp, php_date_get_date_ce()); zend_call_method_with_1_params(&zv_tmp, NULL, NULL, "__construct", NULL, zv_arg); if (EG(exception)) { zend_object_store_ctor_failed(Z_OBJ(zv_tmp) TSRMLS_CC); goto error; } zv_datetime = &zv_tmp; } else { zv_datetime = zv_arg; } datetime = Z_PHPDATE_P(zv_datetime); if (!datetime->time) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: DateTime object is unconstructed", 0 TSRMLS_CC); goto error; } zend_call_method_with_0_params(zv_datetime, php_date_get_date_ce(), NULL, "gettimestamp", &zv_timestamp); if (Z_TYPE(zv_timestamp) != IS_LONG) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: bad DateTime; call to " "DateTime::getTimestamp() failed", 0 TSRMLS_CC); zval_ptr_dtor(&zv_timestamp); goto error; } if (!datetime->time->is_localtime) { timeZone = TimeZone::getGMT()->clone(); } else { timeZone = timezone_convert_datetimezone(datetime->time->zone_type, datetime, 1, NULL, "intlcal_from_date_time" TSRMLS_CC); if (timeZone == NULL) { goto error; } } if (!locale_str) { locale_str = const_cast<char*>(intl_locale_get_default(TSRMLS_C)); } cal = Calendar::createInstance(timeZone, Locale::createFromName(locale_str), status); if (cal == NULL) { delete timeZone; intl_error_set(NULL, status, "intlcal_from_date_time: " "error creating ICU Calendar object", 0 TSRMLS_CC); goto error; } cal->setTime(((UDate)Z_LVAL(zv_timestamp)) * 1000., status); if (U_FAILURE(status)) { /* time zone was adopted by cal; should not be deleted here */ delete cal; intl_error_set(NULL, status, "intlcal_from_date_time: " "error creating ICU Calendar::setTime()", 0 TSRMLS_CC); goto error; } calendar_object_create(return_value, cal TSRMLS_CC); error: if (zv_datetime && zv_datetime != zv_arg) { zval_ptr_dtor(zv_datetime); } }
/* {{{ timezone_process_timezone_argument * TimeZone argument processor. outside_error may be NULL (for static functions/constructors) */ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone, intl_error *outside_error, const char *func) { zval local_zv_tz; char *message = NULL; TimeZone *timeZone; if (zv_timezone == NULL || Z_TYPE_P(zv_timezone) == IS_NULL) { timelib_tzinfo *tzinfo = get_timezone_info(); ZVAL_STRING(&local_zv_tz, tzinfo->name); zv_timezone = &local_zv_tz; } else { ZVAL_NULL(&local_zv_tz); } if (Z_TYPE_P(zv_timezone) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv_timezone), TimeZone_ce_ptr)) { TimeZone_object *to = Z_INTL_TIMEZONE_P(zv_timezone); if (to->utimezone == NULL) { spprintf(&message, 0, "%s: passed IntlTimeZone is not " "properly constructed", func); if (message) { intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1); efree(message); } zval_dtor(&local_zv_tz); return NULL; } timeZone = to->utimezone->clone(); if (timeZone == NULL) { spprintf(&message, 0, "%s: could not clone TimeZone", func); if (message) { intl_errors_set(outside_error, U_MEMORY_ALLOCATION_ERROR, message, 1); efree(message); } zval_dtor(&local_zv_tz); return NULL; } } else if (Z_TYPE_P(zv_timezone) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv_timezone), php_date_get_timezone_ce())) { php_timezone_obj *tzobj = Z_PHPTIMEZONE_P(zv_timezone); zval_dtor(&local_zv_tz); return timezone_convert_datetimezone(tzobj->type, tzobj, 0, outside_error, func); } else { UnicodeString id, gottenId; UErrorCode status = U_ZERO_ERROR; /* outside_error may be NULL */ convert_to_string_ex(zv_timezone); if (intl_stringFromChar(id, Z_STRVAL_P(zv_timezone), Z_STRLEN_P(zv_timezone), &status) == FAILURE) { spprintf(&message, 0, "%s: Time zone identifier given is not a " "valid UTF-8 string", func); if (message) { intl_errors_set(outside_error, status, message, 1); efree(message); } zval_dtor(&local_zv_tz); return NULL; } timeZone = TimeZone::createTimeZone(id); if (timeZone == NULL) { spprintf(&message, 0, "%s: could not create time zone", func); if (message) { intl_errors_set(outside_error, U_MEMORY_ALLOCATION_ERROR, message, 1); efree(message); } zval_dtor(&local_zv_tz); return NULL; } if (timeZone->getID(gottenId) != id) { spprintf(&message, 0, "%s: no such time zone: '%s'", func, Z_STRVAL_P(zv_timezone)); if (message) { intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1); efree(message); } zval_dtor(&local_zv_tz); delete timeZone; return NULL; } } zval_dtor(&local_zv_tz); return timeZone; }
U_CFUNC PHP_FUNCTION(intlcal_from_date_time) { zval **zv_arg, *zv_datetime = NULL; double millis; php_date_obj *datetime; char *locale_str = NULL; int locale_str_len; TimeZone *timeZone; UErrorCode status = U_ZERO_ERROR; Calendar *cal; intl_error_reset(NULL TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|s!", &zv_arg, &locale_str, &locale_str_len) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: bad arguments", 0 TSRMLS_CC); RETURN_NULL(); } if (!(Z_TYPE_PP(zv_arg) == IS_OBJECT && instanceof_function( Z_OBJCE_PP(zv_arg), php_date_get_date_ce() TSRMLS_CC))) { ALLOC_INIT_ZVAL(zv_datetime); object_init_ex(zv_datetime, php_date_get_date_ce()); zend_call_method_with_1_params(&zv_datetime, NULL, NULL, "__construct", NULL, *zv_arg); if (EG(exception)) { zend_object_store_ctor_failed(zv_datetime TSRMLS_CC); goto error; } } else { zv_datetime = *zv_arg; } datetime = (php_date_obj*)zend_object_store_get_object(zv_datetime TSRMLS_CC); if (!datetime->time) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: DateTime object is unconstructed", 0 TSRMLS_CC); goto error; } if (intl_datetime_decompose(zv_datetime, &millis, NULL, NULL, "intlcal_from_date_time" TSRMLS_CC) == FAILURE) { goto error; } if (!datetime->time->is_localtime) { timeZone = TimeZone::getGMT()->clone(); } else { timeZone = timezone_convert_datetimezone(datetime->time->zone_type, datetime, 1, NULL, "intlcal_from_date_time" TSRMLS_CC); if (timeZone == NULL) { goto error; } } if (!locale_str) { locale_str = const_cast<char*>(intl_locale_get_default(TSRMLS_C)); } cal = Calendar::createInstance(timeZone, Locale::createFromName(locale_str), status); if (cal == NULL) { delete timeZone; intl_error_set(NULL, status, "intlcal_from_date_time: " "error creating ICU Calendar object", 0 TSRMLS_CC); goto error; } cal->setTime(millis, status); if (U_FAILURE(status)) { /* time zone was adopted by cal; should not be deleted here */ delete cal; intl_error_set(NULL, status, "intlcal_from_date_time: " "error creating ICU Calendar::setTime()", 0 TSRMLS_CC); goto error; } calendar_object_create(return_value, cal TSRMLS_CC); error: if (zv_datetime != *zv_arg) { zval_ptr_dtor(&zv_datetime); } }