diff options
author | Gustavo André dos Santos Lopes <cataphract@php.net> | 2012-04-01 11:11:40 +0200 |
---|---|---|
committer | Gustavo André dos Santos Lopes <cataphract@php.net> | 2012-04-01 23:28:00 +0100 |
commit | 5e65205a8f52d25635bb4e7619a4b0216aefa4b8 (patch) | |
tree | 5c9984f097fe230ad52dbd48ad8895056c108960 | |
parent | 6c891f33d73afc50c3d79e982c5752fc3f5df85f (diff) | |
download | php-git-5e65205a8f52d25635bb4e7619a4b0216aefa4b8.tar.gz |
Initial checkin of calendar/timezone code.
143 files changed, 8044 insertions, 6 deletions
diff --git a/ext/intl/calendar/calendar_class.cpp b/ext/intl/calendar/calendar_class.cpp new file mode 100644 index 0000000000..d4c482876a --- /dev/null +++ b/ext/intl/calendar/calendar_class.cpp @@ -0,0 +1,509 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <unicode/calendar.h> +#include <unicode/gregocal.h> + +extern "C" { +#define USE_TIMEZONE_POINTER 1 +#include "../timezone/timezone_class.h" +#define USE_CALENDAR_POINTER 1 +#include "calendar_class.h" +#include "calendar_methods.h" +#include "gregoriancalendar_methods.h" +#include <zend_exceptions.h> +#include <assert.h> +} + +/* {{{ Global variables */ +zend_class_entry *Calendar_ce_ptr; +zend_class_entry *GregorianCalendar_ce_ptr; +zend_object_handlers Calendar_handlers; +/* }}} */ + +U_CFUNC void calendar_object_create(zval *object, + Calendar *calendar TSRMLS_DC) +{ + UClassID classId = calendar->getDynamicClassID(); + zend_class_entry *ce; + + //if (dynamic_cast<GregorianCalendar*>(calendar) != NULL) { + if (classId == GregorianCalendar::getStaticClassID()) { + ce = GregorianCalendar_ce_ptr; + } else { + ce = Calendar_ce_ptr; + } + + object_init_ex(object, ce); + calendar_object_construct(object, calendar TSRMLS_CC); +} + +U_CFUNC void calendar_object_construct(zval *object, + Calendar *calendar TSRMLS_DC) +{ + Calendar_object *co; + + CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; //populate to from object + assert(co->ucal == NULL); + co->ucal = (Calendar*)calendar; +} + +/* {{{ clone handler for Calendar */ +static zend_object_value Calendar_clone_obj(zval *object TSRMLS_DC) +{ + Calendar_object *co_orig, + *co_new; + zend_object_value ret_val; + intl_error_reset(NULL TSRMLS_CC); + + co_orig = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + intl_error_reset(INTL_DATA_ERROR_P(co_orig) TSRMLS_CC); + + ret_val = Calendar_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); + co_new = (Calendar_object*)zend_object_store_get_object_by_handle(ret_val.handle TSRMLS_CC); + + zend_objects_clone_members(&co_new->zo, ret_val, + &co_orig->zo, Z_OBJ_HANDLE_P(object) TSRMLS_CC); + + if (co_orig->ucal != NULL) { + Calendar *newCalendar; + + newCalendar = co_orig->ucal->clone(); + if (!newCalendar) { + char *err_msg; + intl_errors_set_code(CALENDAR_ERROR_P(co_orig), + U_MEMORY_ALLOCATION_ERROR TSRMLS_CC); + intl_errors_set_custom_msg(CALENDAR_ERROR_P(co_orig), + "Could not clone IntlCalendar", 0 TSRMLS_CC); + err_msg = intl_error_get_message(CALENDAR_ERROR_P(co_orig) TSRMLS_CC); + zend_throw_exception(NULL, err_msg, 0 TSRMLS_CC); + efree(err_msg); + } else { + co_new->ucal = newCalendar; + } + } else { + zend_throw_exception(NULL, "Cannot clone unconstructed IntlCalendar", 0 TSRMLS_CC); + } + + return ret_val; +} +/* }}} */ + +static const struct { + UCalendarDateFields field; + const char *name; +} debug_info_fields[] = { + {UCAL_ERA, "era"}, + {UCAL_YEAR, "year"}, + {UCAL_MONTH, "month"}, + {UCAL_WEEK_OF_YEAR, "week of year"}, + {UCAL_WEEK_OF_MONTH, "week of month"}, + {UCAL_DAY_OF_YEAR, "day of year"}, + {UCAL_DAY_OF_MONTH, "day of month"}, + {UCAL_DAY_OF_WEEK, "day of week"}, + {UCAL_DAY_OF_WEEK_IN_MONTH, "day of week in month"}, + {UCAL_AM_PM, "AM/PM"}, + {UCAL_HOUR, "hour"}, + {UCAL_HOUR_OF_DAY, "hour of day"}, + {UCAL_MINUTE, "minute"}, + {UCAL_SECOND, "second"}, + {UCAL_MILLISECOND, "millisecond"}, + {UCAL_ZONE_OFFSET, "zone offset"}, + {UCAL_DST_OFFSET, "DST offset"}, + {UCAL_YEAR_WOY, "year for week of year"}, + {UCAL_DOW_LOCAL, "localized day of week"}, + {UCAL_EXTENDED_YEAR, "extended year"}, + {UCAL_JULIAN_DAY, "julian day"}, + {UCAL_MILLISECONDS_IN_DAY, "milliseconds in day"}, + {UCAL_IS_LEAP_MONTH, "is leap month"}, +}; + +/* {{{ get_debug_info handler for Calendar */ +static HashTable *Calendar_get_debug_info(zval *object, int *is_temp TSRMLS_DC) +{ + zval zv = zval_used_for_init, + *zfields; + Calendar_object *co; + const Calendar *cal; + + array_init_size(&zv, 8); + + co = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + cal = co->ucal; + + if (cal == NULL) { + add_assoc_bool_ex(&zv, "valid", sizeof("valid"), 0); + return Z_ARRVAL(zv); + } + + add_assoc_bool_ex(&zv, "valid", sizeof("valid"), 1); + + add_assoc_string_ex(&zv, "type", sizeof("type"), + const_cast<char*>(cal->getType()), 1); + + { + zval ztz = zval_used_for_init, + *ztz_debug; + int is_tmp; + HashTable *debug_info; + + timezone_object_construct(&cal->getTimeZone(), &ztz , 0 TSRMLS_CC); + debug_info = Z_OBJ_HANDLER(ztz, get_debug_info)(&ztz, &is_tmp TSRMLS_CC); + assert(is_tmp == 1); + + ALLOC_INIT_ZVAL(ztz_debug); + Z_TYPE_P(ztz_debug) = IS_ARRAY; + Z_ARRVAL_P(ztz_debug) = debug_info; + add_assoc_zval_ex(&zv, "timeZone", sizeof("timeZone"), ztz_debug); + } + + { + UErrorCode uec = U_ZERO_ERROR; + Locale locale = cal->getLocale(ULOC_VALID_LOCALE, uec); + if (U_SUCCESS(uec)) { + add_assoc_string_ex(&zv, "locale", sizeof("locale"), + const_cast<char*>(locale.getName()), 1); + } else { + add_assoc_string_ex(&zv, "locale", sizeof("locale"), + const_cast<char*>(u_errorName(uec)), 1); + } + } + + ALLOC_INIT_ZVAL(zfields); + array_init_size(zfields, UCAL_FIELD_COUNT); + + for (int i = 0; + i < sizeof(debug_info_fields) / sizeof(*debug_info_fields); + i++) { + UErrorCode uec = U_ZERO_ERROR; + const char *name = debug_info_fields[i].name; + int32_t res = cal->get(debug_info_fields[i].field, uec); + if (U_SUCCESS(uec)) { + add_assoc_long(zfields, name, (long)res); + } else { + add_assoc_string(zfields, name, const_cast<char*>(u_errorName(uec)), 1); + } + } + + add_assoc_zval_ex(&zv, "fields", sizeof("fields"), zfields); + + *is_temp = 1; + + return Z_ARRVAL(zv); +} +/* }}} */ + +/* {{{ void calendar_object_init(Calendar_object* to) + * Initialize internals of Calendar_object not specific to zend standard objects. + */ +static void calendar_object_init(Calendar_object *co TSRMLS_DC) +{ + intl_error_init(CALENDAR_ERROR_P(co) TSRMLS_CC); + co->ucal = NULL; +} +/* }}} */ + +/* {{{ Calendar_objects_dtor */ +static void Calendar_objects_dtor(void *object, + zend_object_handle handle TSRMLS_DC) +{ + zend_objects_destroy_object((zend_object*)object, handle TSRMLS_CC); +} +/* }}} */ + +/* {{{ Calendar_objects_free */ +static void Calendar_objects_free(zend_object *object TSRMLS_DC) +{ + Calendar_object* co = (Calendar_object*) object; + + if (co->ucal) { + delete co->ucal; + co->ucal = NULL; + } + intl_error_reset(CALENDAR_ERROR_P(co) TSRMLS_CC); + + zend_object_std_dtor(&co->zo TSRMLS_CC); + + efree(co); +} +/* }}} */ + +/* {{{ Calendar_object_create */ +static zend_object_value Calendar_object_create(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value retval; + Calendar_object* intern; + + intern = (Calendar_object*)ecalloc(1, sizeof(Calendar_object)); + + zend_object_std_init(&intern->zo, ce TSRMLS_CC); +#if PHP_VERSION_ID < 50399 + zend_hash_copy(intern->zo.properties, &(ce->default_properties), + (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); +#else + object_properties_init((zend_object*) intern, ce); +#endif + calendar_object_init(intern TSRMLS_CC); + + retval.handle = zend_objects_store_put( + intern, + Calendar_objects_dtor, + (zend_objects_free_object_storage_t) Calendar_objects_free, + NULL TSRMLS_CC); + + retval.handlers = &Calendar_handlers; + + return retval; +} +/* }}} */ + +/* {{{ Calendar methods arguments info */ + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_void, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_field, 0, 0, 1) + ZEND_ARG_INFO(0, field) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_dow, 0, 0, 1) + ZEND_ARG_INFO(0, dayOfWeek) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_other_cal, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_date, 0, 0, 1) + ZEND_ARG_INFO(0, date) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_date_optional, 0, 0, 0) + ZEND_ARG_INFO(0, date) +ZEND_END_ARG_INFO() + + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_createInstance, 0, 0, 0) + ZEND_ARG_INFO(0, timeZone) + ZEND_ARG_INFO(0, locale) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_get_keyword_values_for_locale, 0, 0, 3) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, locale) + ZEND_ARG_INFO(0, commonlyUsed) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_add, 0, 0, 2) + ZEND_ARG_INFO(0, field) + ZEND_ARG_INFO(0, amount) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_setTimeZone, 0, 0, 2) + ZEND_ARG_OBJ_INFO(0, timeZone, IntlTimeZone, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_set, 0, 0, 2) + ZEND_ARG_INFO(0, fieldOrYear) + ZEND_ARG_INFO(0, valueOrMonth) + ZEND_ARG_INFO(0, dayOfMonth) + ZEND_ARG_INFO(0, hour) + ZEND_ARG_INFO(0, minute) + ZEND_ARG_INFO(0, second) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_roll, 0, 0, 2) + ZEND_ARG_INFO(0, field) + ZEND_ARG_INFO(0, amountOrUpOrDown) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_clear, 0, 0, 0) + ZEND_ARG_INFO(0, field) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_field_difference, 0, 0, 2) + ZEND_ARG_INFO(0, when) + ZEND_ARG_INFO(0, field) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_get_locale, 0, 0, 1) + ZEND_ARG_INFO(0, localeType) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_setLenient, 0, 0, 1) + ZEND_ARG_INFO(0, isLenient) +ZEND_END_ARG_INFO() + +/* Gregorian Calendar */ +ZEND_BEGIN_ARG_INFO_EX(ainfo_gregcal___construct, 0, 0, 0) + ZEND_ARG_INFO(0, timeZoneOrYear) + ZEND_ARG_INFO(0, localeOrMonth) + ZEND_ARG_INFO(0, dayOfMonth) + ZEND_ARG_INFO(0, hour) + ZEND_ARG_INFO(0, minute) + ZEND_ARG_INFO(0, second) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_gregcal_isLeapYear, 0, 0, 1) + ZEND_ARG_INFO(0, year) +ZEND_END_ARG_INFO() + +/* }}} */ + +/* {{{ Calendar_class_functions + * Every 'IntlCalendar' class method has an entry in this table + */ +static const zend_function_entry Calendar_class_functions[] = { + PHP_ME(IntlCalendar, __construct, ainfo_cal_void, ZEND_ACC_PRIVATE) + PHP_ME_MAPPING(createInstance, intlcal_create_instance, ainfo_cal_createInstance, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getKeywordValuesForLocale, intlcal_get_keyword_values_for_locale, ainfo_cal_get_keyword_values_for_locale, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getNow, intlcal_get_now, ainfo_cal_void, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getAvailableLocales, intlcal_get_available_locales, ainfo_cal_void, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(get, intlcal_get, ainfo_cal_field, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getTime, intlcal_get_time, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(setTime, intlcal_set_time, ainfo_cal_date, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(add, intlcal_add, ainfo_cal_add, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(setTimeZone, intlcal_set_time_zone, ainfo_cal_setTimeZone, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(after, intlcal_after, ainfo_cal_other_cal, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(before, intlcal_before, ainfo_cal_other_cal, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(set, intlcal_set, ainfo_cal_set, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(roll, intlcal_roll, ainfo_cal_roll, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(clear, intlcal_clear, ainfo_cal_clear, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(fieldDifference, intlcal_field_difference, ainfo_cal_field_difference, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getActualMaximum, intlcal_get_actual_maximum, ainfo_cal_field, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getActualMinimum, intlcal_get_actual_minimum, ainfo_cal_field, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getDayOfWeekType, intlcal_get_day_of_week_type, ainfo_cal_dow, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getFirstDayOfWeek, intlcal_get_first_day_of_week, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getGreatestMinimum, intlcal_get_greatest_minimum, ainfo_cal_field, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getLeastMaximum, intlcal_get_least_maximum, ainfo_cal_field, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getLocale, intlcal_get_locale, ainfo_cal_get_locale, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getMaximum, intlcal_get_maximum, ainfo_cal_field, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getMinimalDaysInFirstWeek, intlcal_get_minimal_days_in_first_week, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getMinimum, intlcal_get_minimum, ainfo_cal_field, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getTimeZone, intlcal_get_time_zone, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getType, intlcal_get_type, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getWeekendTransition,intlcal_get_weekend_transition, ainfo_cal_dow, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(inDaylightTime, intlcal_in_daylight_time, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(isEquivalentTo, intlcal_is_equivalent_to, ainfo_cal_other_cal, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(isLenient, intlcal_is_lenient, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(isSet, intlcal_is_set, ainfo_cal_field, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(isWeekend, intlcal_is_weekend, ainfo_cal_date_optional, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(setFirstDayOfWeek, intlcal_set_first_day_of_week, ainfo_cal_dow, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(setLenient, intlcal_set_lenient, ainfo_cal_setLenient, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(equals, intlcal_equals, ainfo_cal_other_cal, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getErrorCode, intlcal_get_error_code, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getErrorMessage, intlcal_get_error_message, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_FE_END +}; +/* }}} */ + +/* {{{ GregorianCalendar_class_functions + */ +static const zend_function_entry GregorianCalendar_class_functions[] = { + PHP_ME(IntlGregorianCalendar, __construct, ainfo_gregcal___construct, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(setGregorianChange, intlgregcal_set_gregorian_change, ainfo_cal_date, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getGregorianChange, intlgregcal_get_gregorian_change, ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(isLeapYear, intlgregcal_is_leap_year, ainfo_gregcal_isLeapYear, ZEND_ACC_PUBLIC) + PHP_FE_END +}; +/* }}} */ + + +/* {{{ calendar_register_IntlCalendar_class + * Initialize 'IntlCalendar' class + */ +void calendar_register_IntlCalendar_class(TSRMLS_D) +{ + zend_class_entry ce; + + /* Create and register 'IntlCalendar' class. */ + INIT_CLASS_ENTRY(ce, "IntlCalendar", Calendar_class_functions); + ce.create_object = Calendar_object_create; + Calendar_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC); + if (!Calendar_ce_ptr) { + //can't happen now without bigger problems before + php_error_docref0(NULL TSRMLS_CC, E_ERROR, + "IntlCalendar: class registration has failed."); + return; + } + memcpy( &Calendar_handlers, zend_get_std_object_handlers(), + sizeof Calendar_handlers); + Calendar_handlers.clone_obj = Calendar_clone_obj; + Calendar_handlers.get_debug_info = Calendar_get_debug_info; + + /* Create and register 'IntlGregorianCalendar' class. */ + INIT_CLASS_ENTRY(ce, "IntlGregorianCalendar", GregorianCalendar_class_functions); + GregorianCalendar_ce_ptr = zend_register_internal_class_ex(&ce, + Calendar_ce_ptr, NULL TSRMLS_CC); + if (!GregorianCalendar_ce_ptr) { + //can't happen know without bigger problems before + php_error_docref0(NULL TSRMLS_CC, E_ERROR, + "IntlGregorianCalendar: class registration has failed."); + return; + } + + /* Declare 'IntlCalendar' class constants */ +#define CALENDAR_DECL_LONG_CONST(name, val) \ + zend_declare_class_constant_long(Calendar_ce_ptr, name, sizeof(name) - 1, \ + val TSRMLS_CC) + + CALENDAR_DECL_LONG_CONST("FIELD_ERA", UCAL_ERA); + CALENDAR_DECL_LONG_CONST("FIELD_YEAR", UCAL_YEAR); + CALENDAR_DECL_LONG_CONST("FIELD_MONTH", UCAL_MONTH); + CALENDAR_DECL_LONG_CONST("FIELD_WEEK_OF_YEAR", UCAL_WEEK_OF_YEAR); + CALENDAR_DECL_LONG_CONST("FIELD_WEEK_OF_MONTH", UCAL_WEEK_OF_MONTH); + CALENDAR_DECL_LONG_CONST("FIELD_DATE", UCAL_DATE); + CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_YEAR", UCAL_DAY_OF_YEAR); + CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_WEEK", UCAL_DAY_OF_WEEK); + CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_WEEK_IN_MONTH", UCAL_DAY_OF_WEEK_IN_MONTH); + CALENDAR_DECL_LONG_CONST("FIELD_AM_PM", UCAL_AM_PM); + CALENDAR_DECL_LONG_CONST("FIELD_HOUR", UCAL_HOUR); + CALENDAR_DECL_LONG_CONST("FIELD_HOUR_OF_DAY", UCAL_HOUR_OF_DAY); + CALENDAR_DECL_LONG_CONST("FIELD_HOUR", UCAL_HOUR); + CALENDAR_DECL_LONG_CONST("FIELD_HOUR_OF_DAY", UCAL_HOUR_OF_DAY); + CALENDAR_DECL_LONG_CONST("FIELD_MINUTE", UCAL_MINUTE); + CALENDAR_DECL_LONG_CONST("FIELD_SECOND", UCAL_SECOND); + CALENDAR_DECL_LONG_CONST("FIELD_MILLISECOND", UCAL_MILLISECOND); + CALENDAR_DECL_LONG_CONST("FIELD_ZONE_OFFSET", UCAL_ZONE_OFFSET); + CALENDAR_DECL_LONG_CONST("FIELD_DST_OFFSET", UCAL_DST_OFFSET); + CALENDAR_DECL_LONG_CONST("FIELD_YEAR_WOY", UCAL_YEAR_WOY); + CALENDAR_DECL_LONG_CONST("FIELD_DOW_LOCAL", UCAL_DOW_LOCAL); + CALENDAR_DECL_LONG_CONST("FIELD_EXTENDED_YEAR", UCAL_EXTENDED_YEAR); + CALENDAR_DECL_LONG_CONST("FIELD_JULIAN_DAY", UCAL_JULIAN_DAY); + CALENDAR_DECL_LONG_CONST("FIELD_MILLISECONDS_IN_DAY", UCAL_MILLISECONDS_IN_DAY); + CALENDAR_DECL_LONG_CONST("FIELD_IS_LEAP_MONTH", UCAL_IS_LEAP_MONTH); + CALENDAR_DECL_LONG_CONST("FIELD_FIELD_COUNT ", UCAL_FIELD_COUNT); + CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_MONTH", UCAL_DAY_OF_MONTH); + + CALENDAR_DECL_LONG_CONST("DOW_SUNDAY", UCAL_SUNDAY); + CALENDAR_DECL_LONG_CONST("DOW_MONDAY", UCAL_MONDAY); + CALENDAR_DECL_LONG_CONST("DOW_TUESDAY", UCAL_TUESDAY); + CALENDAR_DECL_LONG_CONST("DOW_WEDNESDAY", UCAL_WEDNESDAY); + CALENDAR_DECL_LONG_CONST("DOW_THURSDAY", UCAL_THURSDAY); + CALENDAR_DECL_LONG_CONST("DOW_FRIDAY", UCAL_FRIDAY); + CALENDAR_DECL_LONG_CONST("DOW_SATURDAY", UCAL_SATURDAY); + + CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKDAY", UCAL_WEEKDAY); + CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND", UCAL_WEEKEND); + CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_OFFSET", UCAL_WEEKEND_ONSET); + CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_CEASE", UCAL_WEEKEND_CEASE); + +} +/* }}} */ diff --git a/ext/intl/calendar/calendar_class.h b/ext/intl/calendar/calendar_class.h new file mode 100644 index 0000000000..c41c021fcd --- /dev/null +++ b/ext/intl/calendar/calendar_class.h @@ -0,0 +1,67 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ + */ + +#ifndef CALENDAR_CLASS_H +#define CALENDAR_CLASS_H + +//redefinition of inline in PHP headers causes problems, so include this before +#include <math.h> + +#include <php.h> +#include "intl_error.h" +#include "intl_data.h" + +#ifndef USE_CALENDAR_POINTER +typedef void Calendar; +#endif + +typedef struct { + zend_object zo; + + // error handling + intl_error err; + + // ICU calendar + Calendar* ucal; +} Calendar_object; + +#define CALENDAR_ERROR(co) (co)->err +#define CALENDAR_ERROR_P(co) &(CALENDAR_ERROR(co)) + +#define CALENDAR_ERROR_CODE(co) INTL_ERROR_CODE(CALENDAR_ERROR(co)) +#define CALENDAR_ERROR_CODE_P(co) &(INTL_ERROR_CODE(CALENDAR_ERROR(co))) + +#define CALENDAR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(Calendar, co) +#define CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(Calendar, co) +#define CALENDAR_METHOD_FETCH_OBJECT \ + CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; \ + if (co->ucal == NULL) \ + { \ + intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlCalendar", 0 TSRMLS_CC); \ + RETURN_FALSE; \ + } + +void calendar_object_create(zval *object, Calendar *calendar TSRMLS_DC); + +void calendar_object_construct(zval *object, Calendar *calendar TSRMLS_DC); + +void calendar_register_IntlCalendar_class(TSRMLS_D); + +extern zend_class_entry *Calendar_ce_ptr, + *GregorianCalendar_ce_ptr; +extern zend_object_handlers Calendar_handlers; + +#endif /* #ifndef CALENDAR_CLASS_H */ diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp new file mode 100644 index 0000000000..5eb0c13a50 --- /dev/null +++ b/ext/intl/calendar/calendar_methods.cpp @@ -0,0 +1,1062 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <unicode/locid.h> +#include <unicode/calendar.h> +#include <unicode/ustring.h> +#include "../intl_convertcpp.h" +extern "C" { +#define USE_TIMEZONE_POINTER 1 +#include "../timezone/timezone_class.h" +#define USE_CALENDAR_POINTER 1 +#include "calendar_class.h" +#include "../intl_convert.h" +#include "../locale/locale.h" +#include <zend_exceptions.h> +} +#include "../common/common_enum.h" + +U_CFUNC PHP_METHOD(IntlCalendar, __construct) +{ + zend_throw_exception( NULL, + "An object of this type cannot be created with the new operator", + 0 TSRMLS_CC ); +} + +U_CFUNC PHP_FUNCTION(intlcal_create_instance) +{ + zval **zv_timezone = NULL; + const char *locale_str = NULL; + int dummy; + TimeZone *timeZone; + UErrorCode status = U_ZERO_ERROR; + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|Zs!", + &zv_timezone, &locale_str, &dummy) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_create_calendar: bad arguments", 0 TSRMLS_CC); + RETURN_NULL(); + } + + timeZone = timezone_process_timezone_argument(zv_timezone, + "intlcal_create_instance" TSRMLS_CC); + if (timeZone == NULL) { + RETURN_NULL(); + } + + if (!locale_str) { + locale_str = intl_locale_get_default(TSRMLS_C); + } + + Calendar *cal = Calendar::createInstance(timeZone, + Locale::createFromName(locale_str), status); + if (cal == NULL) { + delete timeZone; + intl_error_set(NULL, status, "Error creating ICU Calendar object", 0 TSRMLS_CC); + RETURN_NULL(); + } + + calendar_object_create(return_value, cal TSRMLS_CC); +} + +class BugStringCharEnumeration : public StringEnumeration +{ +public: + BugStringCharEnumeration(UEnumeration* _uenum) : uenum(_uenum) {} + + ~BugStringCharEnumeration() + { + uenum_close(uenum); + } + + int32_t count(UErrorCode& status) const { + return uenum_count(uenum, &status); + } + + virtual const UnicodeString* snext(UErrorCode& status) + { + int32_t length; + const UChar* str = uenum_unext(uenum, &length, &status); + if (str == 0 || U_FAILURE(status)) { + return 0; + } + return &unistr.setTo(str, length); + } + + virtual const char* next(int32_t *resultLength, UErrorCode &status) + { + int32_t length = -1; + const char* str = uenum_next(uenum, &length, &status); + if (str == 0 || U_FAILURE(status)) { + return 0; + } + if (resultLength) { + //the bug is that uenum_next doesn't set the length + *resultLength = (length == -1) ? strlen(str) : length; + } + + return str; + } + + void reset(UErrorCode& status) + { + uenum_reset(uenum, &status); + } + + virtual UClassID getDynamicClassID() const; + + static UClassID U_EXPORT2 getStaticClassID(); + +private: + UEnumeration *uenum; +}; +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(BugStringCharEnumeration) + +U_CFUNC PHP_FUNCTION(intlcal_get_keyword_values_for_locale) +{ + UErrorCode status = U_ZERO_ERROR; + char *key, + *locale; + int key_len, + locale_len; + zend_bool commonly_used; + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssb", + &key, &key_len, &locale, &locale_len, &commonly_used) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_keyword_values_for_locale: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + //does not work; see ICU bug 9194 +#if 0 + StringEnumeration *se = Calendar::getKeywordValuesForLocale(key, + Locale::createFromName(locale), (UBool)commonly_used, + status); + if (se == NULL) { + intl_error_set(NULL, status, "intlcal_get_keyword_values_for_locale: " + "error calling underlying method", 0 TSRMLS_CC); + RETURN_FALSE; + } +#else + UEnumeration *uenum = ucal_getKeywordValuesForLocale( + key, locale, !!commonly_used, &status); + if (U_FAILURE(status)) { + uenum_close(uenum); + intl_error_set(NULL, status, "intlcal_get_keyword_values_for_locale: " + "error calling underlying method", 0 TSRMLS_CC); + RETURN_FALSE; + } + + StringEnumeration *se = new BugStringCharEnumeration(uenum); +#endif + + IntlIterator_from_StringEnumeration(se, return_value TSRMLS_CC); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_now) +{ + UErrorCode status = U_ZERO_ERROR; + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_now: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + RETURN_DOUBLE((double)Calendar::getNow()); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_available_locales) +{ + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_available_locales: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + int32_t count; + const Locale *availLocales = Calendar::getAvailableLocales(count); + array_init(return_value); + for (int i = 0; i < count; i++) { + Locale locale = availLocales[i]; + add_next_index_string(return_value, locale.getName(), 1); + } +} + +static void _php_intlcal_field_uec_ret_in32t_method( + int32_t (Calendar::*func)(UCalendarDateFields, UErrorCode&) const, + const char *method_name, + INTERNAL_FUNCTION_PARAMETERS) +{ + long field; + char *message; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, Calendar_ce_ptr, &field) == FAILURE) { + spprintf(&message, 0, "%s: bad arguments", method_name); + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); + efree(message); + RETURN_FALSE; + } + + if (field < 0 || field >= UCAL_FIELD_COUNT) { + spprintf(&message, 0, "%s: invalid field", method_name); + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); + efree(message); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + int32_t result = (co->ucal->*func)( + (UCalendarDateFields)field, CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, "Call to ICU method has failed"); + + RETURN_LONG((long)result); +} + +U_CFUNC PHP_FUNCTION(intlcal_get) +{ + _php_intlcal_field_uec_ret_in32t_method(&Calendar::get, + "intlcal_get", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_time) +{ + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + &object, Calendar_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_time: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + UDate result = co->ucal->getTime(CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, + "intlcal_get_time: error calling ICU Calendar::getTime"); + + RETURN_DOUBLE((double)result); +} + +U_CFUNC PHP_FUNCTION(intlcal_set_time) +{ + double time_arg; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Od", + &object, Calendar_ce_ptr, &time_arg) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_time: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + co->ucal->setTime((UDate)time_arg, CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, "Call to underlying method failed"); + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intlcal_add) +{ + long field, + amount; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Oll", &object, Calendar_ce_ptr, &field, &amount) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_add: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (field < 0 || field >= UCAL_FIELD_COUNT) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_add: invalid field", 0 TSRMLS_CC); + RETURN_FALSE; + } + if (amount < INT32_MIN || amount > INT32_MAX) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_add: amount out of bounds", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + co->ucal->add((UCalendarDateFields)field, (int32_t)amount, CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, "intlcal_add: Call to underlying method failed"); + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intlcal_set_time_zone) +{ + zval *zv_timezone; + TimeZone *timeZone; + TimeZone_object *tzo; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "OO!", &object, Calendar_ce_ptr, &zv_timezone, TimeZone_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_time_zone: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + if (zv_timezone == NULL) { + RETURN_TRUE; /* the method does nothing if passed null */ + } + + tzo = static_cast<TimeZone_object*>( + zend_object_store_get_object(zv_timezone TSRMLS_CC)); + if (tzo->utimezone == NULL) { + intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_time_zone: found unsconstructed IntlTimeZone", 0 TSRMLS_CC); + RETURN_FALSE; + } + timeZone = tzo->utimezone->clone(); + if (timeZone == NULL) { + intl_errors_set(&co->err, U_MEMORY_ALLOCATION_ERROR, + "intlcal_set_time_zone: error cloning ICU TimeZone", 0 TSRMLS_CC); + RETURN_FALSE; + } + + co->ucal->adoptTimeZone(timeZone); + + RETURN_TRUE; +} + + +static void _php_intlcal_before_after( + UBool (Calendar::*func)(const Calendar&, UErrorCode&) const, + INTERNAL_FUNCTION_PARAMETERS) +{ + zval *when_object; + Calendar_object *when_co; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "OO", &object, Calendar_ce_ptr, &when_object, Calendar_ce_ptr) + == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_before/after: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + when_co = static_cast<Calendar_object*>( + zend_object_store_get_object(when_object TSRMLS_CC)); + if (when_co->ucal == NULL) { + intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_before/after: Other IntlCalendar was unconstructed", 0 TSRMLS_CC); + RETURN_FALSE; + } + + UBool res = (co->ucal->*func)(*when_co->ucal, CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, "intlcal_before/after: Error calling ICU method"); + + RETURN_BOOL((int)res); +} + +U_CFUNC PHP_FUNCTION(intlcal_after) +{ + _php_intlcal_before_after(&Calendar::after, INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + +U_CFUNC PHP_FUNCTION(intlcal_before) +{ + _php_intlcal_before_after(&Calendar::before, INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + +U_CFUNC PHP_FUNCTION(intlcal_set) +{ + long arg1, arg2, arg3, arg4, arg5, arg6; + zval **args_a[7] = {0}, + ***args = &args_a[0]; + int i; + int variant; /* number of args of the set() overload */ + CALENDAR_METHOD_INIT_VARS; + + /* must come before zpp because zpp would convert the args in the stack to 0 */ + if (ZEND_NUM_ARGS() > (getThis() ? 6 : 7) || + zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set: too many arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + if (!getThis()) { + args++; + } + variant = ZEND_NUM_ARGS() - (getThis() ? 0 : 1); + while (variant > 2 && Z_TYPE_PP(args[variant - 1]) == IS_NULL) { + variant--; + } + + if (variant == 4 || + zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Oll|llll", &object, Calendar_ce_ptr, &arg1, &arg2, &arg3, &arg4, + &arg5, &arg6) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + for (i = 0; i < variant; i++) { + if (Z_LVAL_PP(args[i]) < INT32_MIN || Z_LVAL_PP(args[i]) > INT32_MAX) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set: at least one of the arguments has an absolute " + "value that is too large", 0 TSRMLS_CC); + RETURN_FALSE; + } + } + + if (variant == 2 && (arg1 < 0 || arg1 >= UCAL_FIELD_COUNT)) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set: invalid field", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + if (variant == 2) { + co->ucal->set((UCalendarDateFields)arg1, (int32_t)arg2); + } else if (variant == 3) { + co->ucal->set((int32_t)arg1, (int32_t)arg2, (int32_t)arg3); + } else if (variant == 5) { + co->ucal->set((int32_t)arg1, (int32_t)arg2, (int32_t)arg3, (int32_t)arg4, (int32_t)arg5); + } else if (variant == 6) { + co->ucal->set((int32_t)arg1, (int32_t)arg2, (int32_t)arg3, (int32_t)arg4, (int32_t)arg5, (int32_t)arg6); + } + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intlcal_roll) +{ + long field, + value; + zval **args_a[3] = {0}, + ***args = &args_a[0]; + zend_bool bool_variant_val = (zend_bool)-1; + CALENDAR_METHOD_INIT_VARS; + + if (ZEND_NUM_ARGS() > (getThis() ? 2 :3) || + zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set: too many arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + if (!getThis()) { + args++; + } + if (args[1] != NULL && Z_TYPE_PP(args[1]) == IS_BOOL) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Olb", &object, Calendar_ce_ptr, &field, &bool_variant_val) + == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_roll: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + bool_variant_val = Z_BVAL_PP(args[1]); + } else if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Oll", &object, Calendar_ce_ptr, &field, &value) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_roll: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (field < 0 || field >= UCAL_FIELD_COUNT) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_roll: invalid field", 0 TSRMLS_CC); + RETURN_FALSE; + } + if (bool_variant_val == (zend_bool)-1 && + (value < INT32_MIN || value > INT32_MAX)) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_roll: value out of bounds", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + if (bool_variant_val != (zend_bool)-1) { + co->ucal->roll((UCalendarDateFields)field, (UBool)bool_variant_val, + CALENDAR_ERROR_CODE(co)); + } else { + co->ucal->roll((UCalendarDateFields)field, (int32_t)value, + CALENDAR_ERROR_CODE(co)); + } + INTL_METHOD_CHECK_STATUS(co, "intlcal_roll: Error calling ICU Calendar::roll"); + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intlcal_clear) +{ + zval **args_a[2] = {0}, + ***args = &args_a[0]; + long field; + int variant; + CALENDAR_METHOD_INIT_VARS; + + if (ZEND_NUM_ARGS() > (getThis() ? 1 : 2) || + zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_clear: too many arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + if (!getThis()) { + args++; + } + if (args[0] == NULL || Z_TYPE_PP(args[0]) == IS_NULL) { + zval *dummy; /* we know it's null */ + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + getThis(), "O|z", &object, Calendar_ce_ptr, &dummy) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_clear: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + variant = 0; + } else if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + getThis(), "Ol", &object, Calendar_ce_ptr, &field) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_clear: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } else if (field < 0 || field >= UCAL_FIELD_COUNT) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_clear: invalid field", 0 TSRMLS_CC); + RETURN_FALSE; + } else { + variant = 1; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + if (variant == 0) { + co->ucal->clear(); + } else { + co->ucal->clear((UCalendarDateFields)field); + } + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intlcal_field_difference) +{ + long field; + double when; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Odl", &object, Calendar_ce_ptr, &when, &field) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_field_difference: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (field < 0 || field >= UCAL_FIELD_COUNT) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_field_difference: invalid field", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + int32_t result = co->ucal->fieldDifference((UDate)when, + (UCalendarDateFields)field, CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, + "intlcal_field_difference: Call to ICU method has failed"); + + RETURN_LONG((long)result); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_actual_maximum) +{ + _php_intlcal_field_uec_ret_in32t_method(&Calendar::getActualMaximum, + "intlcal_get_actual_maximum", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_actual_minimum) +{ + _php_intlcal_field_uec_ret_in32t_method(&Calendar::getActualMinimum, + "intlcal_get_actual_minimum", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_day_of_week_type) +{ + long dow; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, Calendar_ce_ptr, &dow) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_day_of_week_type: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (dow < UCAL_SUNDAY || dow > UCAL_SATURDAY) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_day_of_week_type: invalid day of week", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + int32_t result = co->ucal->getDayOfWeekType( + (UCalendarDaysOfWeek)dow, CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, + "intlcal_get_day_of_week_type: Call to ICU method has failed"); + + RETURN_LONG((long)result); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_first_day_of_week) +{ + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O", &object, Calendar_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_first_day_of_week: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + int32_t result = co->ucal->getFirstDayOfWeek(CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, + "intlcal_get_first_day_of_week: Call to ICU method has failed"); + + RETURN_LONG((long)result); +} + +static void _php_intlcal_field_ret_in32t_method( + int32_t (Calendar::*func)(UCalendarDateFields) const, + const char *method_name, + INTERNAL_FUNCTION_PARAMETERS) +{ + long field; + char *message; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, Calendar_ce_ptr, &field) == FAILURE) { + spprintf(&message, 0, "%s: bad arguments", method_name); + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); + efree(message); + RETURN_FALSE; + } + + if (field < 0 || field >= UCAL_FIELD_COUNT) { + spprintf(&message, 0, "%s: invalid field", method_name); + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); + efree(message); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + int32_t result = (co->ucal->*func)((UCalendarDateFields)field); + INTL_METHOD_CHECK_STATUS(co, "Call to ICU method has failed"); + + RETURN_LONG((long)result); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_greatest_minimum) +{ + _php_intlcal_field_ret_in32t_method(&Calendar::getGreatestMinimum, + "intlcal_get_greatest_minimum", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_least_maximum) +{ + _php_intlcal_field_ret_in32t_method(&Calendar::getLeastMaximum, + "intlcal_get_least_maximum", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_locale) +{ + long locale_type; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, Calendar_ce_ptr, &locale_type) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_locale: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_locale: invalid locale type", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + Locale locale = co->ucal->getLocale((ULocDataLocaleType)locale_type, + CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, + "intlcal_get_locale: Call to ICU method has failed"); + + RETURN_STRING(locale.getName(), 1); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_maximum) +{ + _php_intlcal_field_ret_in32t_method(&Calendar::getMaximum, + "intlcal_get_maximum", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_minimal_days_in_first_week) +{ + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O", &object, Calendar_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_minimal_days_in_first_week: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + uint8_t result = co->ucal->getMinimalDaysInFirstWeek(); + INTL_METHOD_CHECK_STATUS(co, + "intlcal_get_first_day_of_week: Call to ICU method has failed"); + + RETURN_LONG((long)result); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_minimum) +{ + _php_intlcal_field_ret_in32t_method(&Calendar::getMinimum, + "intlcal_get_minimum", INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_time_zone) +{ + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O", &object, Calendar_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_time_zone: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + TimeZone *tz = co->ucal->getTimeZone().clone(); + if (tz == NULL) { + intl_error_set(NULL, U_MEMORY_ALLOCATION_ERROR, + "intlcal_get_time_zone: could not clone TimeZone", 0 TSRMLS_CC); + RETURN_FALSE; + } + + timezone_object_construct(tz, return_value, 1 TSRMLS_CC); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_type) +{ + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O", &object, Calendar_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_type: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + RETURN_STRING(co->ucal->getType(), 1); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_weekend_transition) +{ + long dow; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, Calendar_ce_ptr, &dow) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_weekend_transition: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (dow < UCAL_SUNDAY || dow > UCAL_SATURDAY) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_weekend_transition: invalid day of week", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + int32_t res = co->ucal->getWeekendTransition((UCalendarDaysOfWeek)dow, + CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, "intlcal_get_weekend_transition: " + "Error calling ICU method"); + + RETURN_LONG((long)res); +} + +U_CFUNC PHP_FUNCTION(intlcal_in_daylight_time) +{ + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O", &object, Calendar_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_in_daylight_time: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + UBool ret = co->ucal->inDaylightTime(CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, "intlcal_in_daylight_time: " + "Error calling ICU method"); + + RETURN_BOOL((int)ret); +} + +U_CFUNC PHP_FUNCTION(intlcal_is_equivalent_to) +{ + zval *other_object; + Calendar_object *other_co; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "OO", &object, Calendar_ce_ptr, &other_object, Calendar_ce_ptr) + == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_is_equivalent_to: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + other_co = (Calendar_object*)zend_object_store_get_object(other_object TSRMLS_CC); + if (other_co->ucal == NULL) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_is_equivalent_to:" + " Other IntlCalendar is unconstructed", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + RETURN_BOOL((int)co->ucal->isEquivalentTo(*other_co->ucal)); +} + +U_CFUNC PHP_FUNCTION(intlcal_is_lenient) +{ + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O", &object, Calendar_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_is_lenient: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + RETURN_BOOL((int)co->ucal->isLenient()); +} + +U_CFUNC PHP_FUNCTION(intlcal_is_set) +{ + long field; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, Calendar_ce_ptr, &field) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_is_set: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (field < 0 || field >= UCAL_FIELD_COUNT) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_is_set: invalid field", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + RETURN_BOOL((int)co->ucal->isSet((UCalendarDateFields)field)); +} + +U_CFUNC PHP_FUNCTION(intlcal_is_weekend) +{ + double date; + zval *rawDate = NULL; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters_ex(ZEND_PARSE_PARAMS_QUIET, + ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O|z!", &object, Calendar_ce_ptr, &rawDate) == FAILURE + || (rawDate != NULL && + zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O|d", &object, Calendar_ce_ptr, &date) == FAILURE)) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_is_weekend: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + if (rawDate == NULL) { + RETURN_BOOL((int)co->ucal->isWeekend()); + } else { + UBool ret = co->ucal->isWeekend((UDate)date, CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, "intlcal_is_weekend: " + "Error calling ICU method"); + RETURN_BOOL((int)ret); + } +} + + +U_CFUNC PHP_FUNCTION(intlcal_set_first_day_of_week) +{ + long dow; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, Calendar_ce_ptr, &dow) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_first_day_of_week: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (dow < UCAL_SUNDAY || dow > UCAL_SATURDAY) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_first_day_of_week: invalid day of week", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + co->ucal->setFirstDayOfWeek((UCalendarDaysOfWeek)dow); + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intlcal_set_lenient) +{ + zend_bool is_lenient; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ob", &object, Calendar_ce_ptr, &is_lenient) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_lenient: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + co->ucal->setLenient((UBool) is_lenient); + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intlcal_equals) +{ + zval *other_object; + Calendar_object *other_co; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "OO", &object, Calendar_ce_ptr, &other_object, Calendar_ce_ptr) + == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_equals: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + other_co = (Calendar_object *) zend_object_store_get_object(other_object TSRMLS_CC); + if (other_co->ucal == NULL) { + intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_equals: The second IntlCalendar is unconstructed", 0 TSRMLS_CC); + RETURN_FALSE; + } + + UBool result = co->ucal->equals(*other_co->ucal, CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, "intlcal_equals: error calling ICU Calendar::equals"); + + RETURN_BOOL((int)result); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_error_code) +{ + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + &object, Calendar_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_error_code: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + /* Fetch the object (without resetting its last error code ). */ + co = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + if (co == NULL) + RETURN_FALSE; + + RETURN_LONG((long)CALENDAR_ERROR_CODE(co)); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_error_message) +{ + const char* message = NULL; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + &object, Calendar_ce_ptr) == FAILURE) { + intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_get_error_message: bad arguments", 0 TSRMLS_CC ); + RETURN_FALSE; + } + + + /* Fetch the object (without resetting its last error code ). */ + co = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + if (co == NULL) + RETURN_FALSE; + + /* Return last error message. */ + message = intl_error_get_message(CALENDAR_ERROR_P(co) TSRMLS_CC); + RETURN_STRING(message, 0); +} diff --git a/ext/intl/calendar/calendar_methods.h b/ext/intl/calendar/calendar_methods.h new file mode 100644 index 0000000000..93aaa383d0 --- /dev/null +++ b/ext/intl/calendar/calendar_methods.h @@ -0,0 +1,100 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@netcabo.pt> | + +----------------------------------------------------------------------+ + */ + +#ifndef CALENDAR_METHODS_H +#define CALENDAR_METHODS_H + +#include <php.h> + +PHP_METHOD(IntlCalendar, __construct); + +PHP_FUNCTION(intlcal_create_instance); + +PHP_FUNCTION(intlcal_get_keyword_values_for_locale); + +PHP_FUNCTION(intlcal_get_now); + +PHP_FUNCTION(intlcal_get_available_locales); + +PHP_FUNCTION(intlcal_get); + +PHP_FUNCTION(intlcal_get_time); + +PHP_FUNCTION(intlcal_set_time); + +PHP_FUNCTION(intlcal_add); + +PHP_FUNCTION(intlcal_set_time_zone); + +PHP_FUNCTION(intlcal_after); + +PHP_FUNCTION(intlcal_before); + +PHP_FUNCTION(intlcal_set); + +PHP_FUNCTION(intlcal_roll); + +PHP_FUNCTION(intlcal_clear); + +PHP_FUNCTION(intlcal_field_difference); + +PHP_FUNCTION(intlcal_get_actual_maximum); + +PHP_FUNCTION(intlcal_get_actual_minimum); + +PHP_FUNCTION(intlcal_get_day_of_week_type); + +PHP_FUNCTION(intlcal_get_first_day_of_week); + +PHP_FUNCTION(intlcal_get_greatest_minimum); + +PHP_FUNCTION(intlcal_get_least_maximum); + +PHP_FUNCTION(intlcal_get_locale); + +PHP_FUNCTION(intlcal_get_maximum); + +PHP_FUNCTION(intlcal_get_minimal_days_in_first_week); + +PHP_FUNCTION(intlcal_get_minimum); + +PHP_FUNCTION(intlcal_get_time_zone); + +PHP_FUNCTION(intlcal_get_type); + +PHP_FUNCTION(intlcal_get_weekend_transition); + +PHP_FUNCTION(intlcal_in_daylight_time); + +PHP_FUNCTION(intlcal_is_equivalent_to); + +PHP_FUNCTION(intlcal_is_lenient); + +PHP_FUNCTION(intlcal_is_set); + +PHP_FUNCTION(intlcal_is_weekend); + +PHP_FUNCTION(intlcal_set_first_day_of_week); + +PHP_FUNCTION(intlcal_set_lenient); + +PHP_FUNCTION(intlcal_equals); + +PHP_FUNCTION(intlcal_get_error_code); + +PHP_FUNCTION(intlcal_get_error_message); + +#endif /* #ifndef CALENDAR_METHODS_H */ diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp new file mode 100644 index 0000000000..712521a5ea --- /dev/null +++ b/ext/intl/calendar/gregoriancalendar_methods.cpp @@ -0,0 +1,251 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <unicode/locid.h> +#include <unicode/calendar.h> +#include <unicode/gregocal.h> +extern "C" { +#define USE_TIMEZONE_POINTER 1 +#include "../timezone/timezone_class.h" +#define USE_CALENDAR_POINTER 1 +#include "calendar_class.h" +#include "../locale/locale.h" +/* avoid redefinition of int8_t, already defined in unicode/pwin32.h */ +#define _MSC_STDINT_H_ 1 +#include <ext/date/php_date.h> +} + +static inline GregorianCalendar *fetch_greg(Calendar_object *co) { + return (GregorianCalendar*)co->ucal; +} + +static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) +{ + zval *object = getThis(); + zval **tz_object = NULL; + zval **args_a[6] = {0}, + ***args = &args_a[0]; + char *locale = NULL; + int locale_len; + long largs[6]; + UErrorCode status = U_ZERO_ERROR; + int variant; + intl_error_reset(NULL TSRMLS_CC); + + // parameter number validation / variant determination + if (ZEND_NUM_ARGS() > 6 || + zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: too many arguments", 0 TSRMLS_CC); + RETURN_NULL(); + } + for (variant = ZEND_NUM_ARGS(); + variant > 0 && Z_TYPE_PP(args[variant - 1]) == IS_NULL; + variant--) {} + if (variant == 4) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: no variant with 4 arguments " + "(excluding trailing NULLs)", 0 TSRMLS_CC); + RETURN_NULL(); + } + + // argument parsing + if (variant <= 2) { + if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2) TSRMLS_CC, + "|Z!s!", &tz_object, &locale, &locale_len) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: bad arguments", 0 TSRMLS_CC); + RETURN_NULL(); + } + } + if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4], + &largs[5]) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: bad arguments", 0 TSRMLS_CC); + RETURN_NULL(); + } + + // instantion of ICU object + GregorianCalendar *gcal; + + if (variant <= 2) { + // From timezone and locale (0 to 2 arguments) + TimeZone *tz = timezone_process_timezone_argument(tz_object, + "intlgregcal_create_instance" TSRMLS_CC); + if (tz == NULL) { + RETURN_NULL(); + } + if (!locale) { + locale = const_cast<char*>(intl_locale_get_default(TSRMLS_C)); + } + + gcal = new GregorianCalendar(tz, Locale::createFromName(locale), + status); + if (U_FAILURE(status)) { + intl_error_set(NULL, status, "intlgregcal_create_instance: error " + "creating ICU GregorianCalendar from time zone and locale", 0 TSRMLS_CC); + if (gcal) { + delete gcal; + } + delete tz; + RETURN_NULL(); + } + } else { + // From date/time (3, 5 or 6 arguments) + for (int i = 0; i < variant; i++) { + if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: at least one of the arguments" + " has an absolute value that is too large", 0 TSRMLS_CC); + RETURN_NULL(); + } + } + + if (variant == 3) { + gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], + (int32_t)largs[2], status); + } else if (variant == 5) { + gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], + (int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], status); + } else if (variant == 6) { + gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], + (int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], (int32_t)largs[5], + status); + } + if (U_FAILURE(status)) { + intl_error_set(NULL, status, "intlgregcal_create_instance: error " + "creating ICU GregorianCalendar from date", 0 TSRMLS_CC); + if (gcal) { + delete gcal; + } + RETURN_NULL(); + } + + timelib_tzinfo *tzinfo = get_timezone_info(TSRMLS_C); + UnicodeString tzstr = UnicodeString::fromUTF8(StringPiece(tzinfo->name)); + if (tzstr.isBogus()) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: could not create UTF-8 string " + "from PHP's default timezone name (see date_default_timezone_get())", + 0 TSRMLS_CC); + delete gcal; + RETURN_NULL(); + } + + TimeZone *tz = TimeZone::createTimeZone(tzstr); + gcal->adoptTimeZone(tz); + } + + Calendar_object *co = (Calendar_object*)zend_object_store_get_object( + return_value TSRMLS_CC); + co->ucal = gcal; +} + +U_CFUNC PHP_FUNCTION(intlgregcal_create_instance) +{ + zval orig; + intl_error_reset(NULL TSRMLS_CC); + + object_init_ex(return_value, GregorianCalendar_ce_ptr); + orig = *return_value; + + _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); + + if (Z_TYPE_P(return_value) == IS_NULL) { + zend_object_store_ctor_failed(&orig TSRMLS_CC); + zval_dtor(&orig); + } +} + +U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct) +{ + zval orig_this = *getThis(); + intl_error_reset(NULL TSRMLS_CC); + + return_value = getThis(); + //changes this to IS_NULL (without first destroying) if there's an error + _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); + + if (Z_TYPE_P(return_value) == IS_NULL) { + zend_object_store_ctor_failed(&orig_this TSRMLS_CC); + zval_dtor(&orig_this); + } +} + +U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change) +{ + double date; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Od", &object, GregorianCalendar_ce_ptr, &date) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_set_gregorian_change: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + fetch_greg(co)->setGregorianChange(date, CALENDAR_ERROR_CODE(co)); + INTL_METHOD_CHECK_STATUS(co, "intlgregcal_set_gregorian_change: error " + "calling ICU method"); + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intlgregcal_get_gregorian_change) +{ + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O", &object, GregorianCalendar_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_get_gregorian_change: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + RETURN_DOUBLE((double)fetch_greg(co)->getGregorianChange()); +} + +U_CFUNC PHP_FUNCTION(intlgregcal_is_leap_year) +{ + long year; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, GregorianCalendar_ce_ptr, &year) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_is_leap_year: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (year < INT32_MIN || year > INT32_MAX) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_is_leap_year: year out of bounds", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + RETURN_BOOL((int)fetch_greg(co)->isLeapYear((int32_t)year)); +} diff --git a/ext/intl/calendar/gregoriancalendar_methods.h b/ext/intl/calendar/gregoriancalendar_methods.h new file mode 100644 index 0000000000..f911752cc7 --- /dev/null +++ b/ext/intl/calendar/gregoriancalendar_methods.h @@ -0,0 +1,32 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ + */ + +#ifndef GREORIANCALENDAR_METHODS_H +#define GREORIANCALENDAR_METHODS_H + +#include <php.h> + +PHP_FUNCTION(intlgregcal_create_instance); + +PHP_METHOD(IntlGregorianCalendar, __construct); + +PHP_FUNCTION(intlgregcal_set_gregorian_change); + +PHP_FUNCTION(intlgregcal_get_gregorian_change); + +PHP_FUNCTION(intlgregcal_is_leap_year); + +#endif diff --git a/ext/intl/common/common_enum.cpp b/ext/intl/common/common_enum.cpp new file mode 100644 index 0000000000..08f6c858cb --- /dev/null +++ b/ext/intl/common/common_enum.cpp @@ -0,0 +1,380 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "common_enum.h" + +extern "C" { +#include "intl_error.h" +#include "intl_data.h" +#include <zend_interfaces.h> +#include <zend_exceptions.h> +} + +static zend_class_entry *IntlIterator_ce_ptr; +static zend_object_handlers IntlIterator_handlers; + +typedef struct { + zend_object zo; + intl_error err; + zend_object_iterator *iterator; +} IntlIterator_object; + +#define INTLITERATOR_ERROR(ii) (ii)->err +#define INTLITERATOR_ERROR_P(ii) &(INTLITERATOR_ERROR(ii)) + +#define INTLITERATOR_ERROR_CODE(ii) INTL_ERROR_CODE(INTLITERATOR_ERROR(ii)) +#define INTLITERATOR_ERROR_CODE_P(ii) &(INTL_ERROR_CODE(INTLITERATOR_ERROR(ii))) + +#define INTLITERATOR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlIterator, ii) +#define INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(IntlIterator, ii) +#define INTLITERATOR_METHOD_FETCH_OBJECT\ + object = getThis(); \ + INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \ + if (ii->iterator == NULL) { \ + intl_errors_set(&ii->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlIterator", 0 TSRMLS_CC); \ + RETURN_FALSE; \ + } + +typedef struct { + zend_object_iterator zoi; + zval *current; + zval *wrapping_obj; + void (*destroy_free_it)(zend_object_iterator *iterator TSRMLS_DC); +} zoi_with_current; + +static void zoi_with_current_dtor(zend_object_iterator *iter TSRMLS_DC) +{ + zoi_with_current *zoiwc = (zoi_with_current*)iter; + + if (zoiwc->wrapping_obj) { + /* we have to copy the pointer because zoiwc->wrapping_obj may be + * changed midway the execution of zval_ptr_dtor() */ + zval *zwo = zoiwc->wrapping_obj; + + /* object is still here, we can rely on it to call this again and + * destroy this object */ + zval_ptr_dtor(&zwo); + } else { + /* Object not here anymore (we've been called by the object free handler) + * Note that the iterator wrapper objects (that also depend on this + * structure) call this function earlier, in the destruction phase, which + * precedes the object free phase. Therefore there's no risk on this + * function being called by the iterator wrapper destructor function and + * not finding the memory of this iterator allocated anymore. */ + iter->funcs->invalidate_current(iter TSRMLS_CC); + zoiwc->destroy_free_it(iter TSRMLS_CC); + efree(iter); + } +} + +static int zoi_with_current_valid(zend_object_iterator *iter TSRMLS_DC) +{ + return ((zoi_with_current*)iter)->current != NULL ? SUCCESS : FAILURE; +} + +static void zoi_with_current_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) +{ + *data = &((zoi_with_current*)iter)->current; +} + +static void zoi_with_current_invalidate_current(zend_object_iterator *iter TSRMLS_DC) +{ + zoi_with_current *zoi_iter = (zoi_with_current*)iter; + if (zoi_iter->current) { + zval_ptr_dtor(&zoi_iter->current); + zoi_iter->current = NULL; //valid would return FAILURE now + } +} + +static void string_enum_current_move_forward(zend_object_iterator *iter TSRMLS_DC) +{ + zoi_with_current *zoi_iter = (zoi_with_current*)iter; + INTLITERATOR_METHOD_INIT_VARS; + + iter->funcs->invalidate_current(iter TSRMLS_CC); + + object = zoi_iter->wrapping_obj; + INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; + + int32_t result_length; + const char *result = ((StringEnumeration*)iter->data)->next( + &result_length, INTLITERATOR_ERROR_CODE(ii)); + + intl_error_set_code(NULL, INTLITERATOR_ERROR_CODE(ii) TSRMLS_CC); + if (U_FAILURE(INTLITERATOR_ERROR_CODE(ii))) { + intl_errors_set_custom_msg(INTL_DATA_ERROR_P(ii), + "Error fetching next iteration element", 0 TSRMLS_CC); + } else if (result) { + MAKE_STD_ZVAL(zoi_iter->current); + ZVAL_STRINGL(zoi_iter->current, result, result_length, 1); + } //else we've reached the end of the enum, nothing more is required +} + +static void string_enum_rewind(zend_object_iterator *iter TSRMLS_DC) +{ + zoi_with_current *zoi_iter = (zoi_with_current*)iter; + INTLITERATOR_METHOD_INIT_VARS; + + if (zoi_iter->current) { + iter->funcs->invalidate_current(iter TSRMLS_CC); + } + + object = zoi_iter->wrapping_obj; + INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; + + ((StringEnumeration*)iter->data)->reset(INTLITERATOR_ERROR_CODE(ii)); + + intl_error_set_code(NULL, INTLITERATOR_ERROR_CODE(ii) TSRMLS_CC); + if (U_FAILURE(INTLITERATOR_ERROR_CODE(ii))) { + intl_errors_set_custom_msg(INTL_DATA_ERROR_P(ii), + "Error resetting enumeration", 0 TSRMLS_CC); + } else { + iter->funcs->move_forward(iter TSRMLS_CC); + } +} + +static void string_enum_destroy_free_it(zend_object_iterator *iter TSRMLS_DC) +{ + delete (StringEnumeration*)iter->data; +} + +static zend_object_iterator_funcs string_enum_object_iterator_funcs = { + zoi_with_current_dtor, + zoi_with_current_valid, + zoi_with_current_get_current_data, + NULL, + string_enum_current_move_forward, + string_enum_rewind, + zoi_with_current_invalidate_current +}; + +U_CFUNC void IntlIterator_from_StringEnumeration(StringEnumeration *se, zval *object TSRMLS_DC) +{ + IntlIterator_object *ii; + object_init_ex(object, IntlIterator_ce_ptr); + ii = (IntlIterator_object*)zend_object_store_get_object(object TSRMLS_CC); + ii->iterator = (zend_object_iterator*)emalloc(sizeof(zoi_with_current)); + ii->iterator->data = (void*)se; + ii->iterator->funcs = &string_enum_object_iterator_funcs; + ii->iterator->index = 0; + ((zoi_with_current*)ii->iterator)->destroy_free_it = string_enum_destroy_free_it; + ((zoi_with_current*)ii->iterator)->wrapping_obj = object; + ((zoi_with_current*)ii->iterator)->current = NULL; +} + +static void IntlIterator_objects_free(zend_object *object TSRMLS_DC) +{ + IntlIterator_object *ii = (IntlIterator_object*) object; + + if (ii->iterator) { + zval **wrapping_objp = &((zoi_with_current*)ii->iterator)->wrapping_obj; + *wrapping_objp = NULL; + ii->iterator->funcs->dtor(ii->iterator TSRMLS_CC); + } + intl_error_reset(INTLITERATOR_ERROR_P(ii) TSRMLS_CC); + + zend_object_std_dtor(&ii->zo TSRMLS_CC); + + efree(ii); +} + +static zend_object_iterator *IntlIterator_get_iterator( + zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) +{ + if (by_ref) { + zend_throw_exception(NULL, + "Iteration by reference is not supported", 0 TSRMLS_CC); + return NULL; + } + + IntlIterator_object *ii = (IntlIterator_object*) + zend_object_store_get_object(object TSRMLS_CC); + + if (ii->iterator == NULL) { + zend_throw_exception(NULL, + "The IntlIterator is not properly constructed", 0 TSRMLS_CC); + return NULL; + } + + zval_add_ref(&object); + + return ii->iterator; +} + +static zend_object_value IntlIterator_object_create(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value retval; + IntlIterator_object *intern; + + intern = (IntlIterator_object*)ecalloc(1, sizeof(IntlIterator_object)); + + zend_object_std_init(&intern->zo, ce TSRMLS_CC); +#if PHP_VERSION_ID < 50399 + zend_hash_copy(intern->zo.properties, &(ce->default_properties), + (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); +#else + object_properties_init((zend_object*) intern, ce); +#endif + intl_error_init(INTLITERATOR_ERROR_P(intern) TSRMLS_CC); + intern->iterator = NULL; + + retval.handle = zend_objects_store_put( + intern, + (zend_objects_store_dtor_t)zend_objects_destroy_object, + (zend_objects_free_object_storage_t)IntlIterator_objects_free, + NULL TSRMLS_CC); + + retval.handlers = &IntlIterator_handlers; + + return retval; +} + +static PHP_METHOD(IntlIterator, current) +{ + zval **data; + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::current: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + ii->iterator->funcs->get_current_data(ii->iterator, &data TSRMLS_CC); + if (data && *data) { + RETURN_ZVAL(*data, 1, 0); + } +} + +static PHP_METHOD(IntlIterator, key) +{ + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::key: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + + if (ii->iterator->funcs->get_current_key) { + char *str_key; + uint str_key_len; + ulong int_key; + + switch (ii->iterator->funcs->get_current_key( + ii->iterator, &str_key, &str_key_len, &int_key TSRMLS_CC)) { + case HASH_KEY_IS_LONG: + RETURN_LONG(int_key); + break; + case HASH_KEY_IS_STRING: + RETURN_STRINGL(str_key, str_key_len-1, 0); + break; + } + } else { + RETURN_LONG(ii->iterator->index); + } +} + +static PHP_METHOD(IntlIterator, next) +{ + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::next: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + ii->iterator->funcs->move_forward(ii->iterator TSRMLS_CC); + /* foreach also advances the index after the last iteration, + * so I see no problem in incrementing the index here unconditionally */ + ii->iterator->index++; +} + +static PHP_METHOD(IntlIterator, rewind) +{ + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::rewind: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + if (ii->iterator->funcs->rewind) { + ii->iterator->funcs->rewind(ii->iterator TSRMLS_CC); + } else { + intl_error_set(NULL, U_UNSUPPORTED_ERROR, + "IntlIterator::rewind: rewind not supported", 0 TSRMLS_CC); + } +} + +static PHP_METHOD(IntlIterator, valid) +{ + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::valid: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + RETURN_BOOL(ii->iterator->funcs->valid(ii->iterator TSRMLS_CC) == SUCCESS); +} + +ZEND_BEGIN_ARG_INFO_EX(ainfo_se_void, 0, 0, 0) +ZEND_END_ARG_INFO() + +static zend_function_entry IntlIterator_class_functions[] = { + PHP_ME(IntlIterator, current, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_ME(IntlIterator, key, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_ME(IntlIterator, next, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_ME(IntlIterator, rewind, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_ME(IntlIterator, valid, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + + +/* {{{ intl_register_IntlIterator_class + * Initialize 'IntlIterator' class + */ +U_CFUNC void intl_register_IntlIterator_class(TSRMLS_D) +{ + zend_class_entry ce; + + /* Create and register 'IntlIterator' class. */ + INIT_CLASS_ENTRY(ce, "IntlIterator", IntlIterator_class_functions); + ce.create_object = IntlIterator_object_create; + IntlIterator_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC); + IntlIterator_ce_ptr->get_iterator = IntlIterator_get_iterator; + zend_class_implements(IntlIterator_ce_ptr TSRMLS_CC, 1, + zend_ce_iterator); + + memcpy(&IntlIterator_handlers, zend_get_std_object_handlers(), + sizeof IntlIterator_handlers); + IntlIterator_handlers.clone_obj = NULL; + +} diff --git a/ext/intl/common/common_enum.h b/ext/intl/common/common_enum.h new file mode 100644 index 0000000000..f3c8bfcead --- /dev/null +++ b/ext/intl/common/common_enum.h @@ -0,0 +1,38 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Vadim Savchuk <vsavchuk@productengine.com> | + | Dmitry Lakhtyuk <dlakhtyuk@productengine.com> | + +----------------------------------------------------------------------+ + */ + +#ifndef INTL_COMMON_ENUM_H +#define INTL_COMMON_ENUM_H + +#include <unicode/umachine.h> +#ifdef __cplusplus +#include <unicode/strenum.h> +extern "C" { +#include <math.h> +#endif +#include <php.h> +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +U_CFUNC void IntlIterator_from_StringEnumeration(StringEnumeration *se, zval *object TSRMLS_DC); +#endif + +U_CFUNC void intl_register_IntlIterator_class(TSRMLS_D); + +#endif // INTL_COMMON_ENUM_H diff --git a/ext/intl/config.m4 b/ext/intl/config.m4 index 0477c7f59d..b1845d8feb 100755 --- a/ext/intl/config.m4 +++ b/ext/intl/config.m4 @@ -20,6 +20,7 @@ if test "$PHP_INTL" != "no"; then PHP_NEW_EXTENSION(intl, php_intl.c \ intl_error.c \ intl_convert.c \ + intl_convertcpp.cpp \ collator/collator.c \ collator/collator_class.c \ collator/collator_sort.c \ @@ -31,6 +32,7 @@ if test "$PHP_INTL" != "no"; then collator/collator_is_numeric.c \ collator/collator_error.c \ common/common_error.c \ + common/common_enum.cpp \ formatter/formatter.c \ formatter/formatter_main.c \ formatter/formatter_class.c \ @@ -65,8 +67,13 @@ if test "$PHP_INTL" != "no"; then transliterator/transliterator.c \ transliterator/transliterator_class.c \ transliterator/transliterator_methods.c \ + timezone/timezone_class.cpp \ + timezone/timezone_methods.cpp \ + calendar/calendar_class.cpp \ + calendar/calendar_methods.cpp \ + calendar/gregoriancalendar_methods.cpp \ idn/idn.c \ - $icu_spoof_src, $ext_shared,,$ICU_INCS) + $icu_spoof_src, $ext_shared,,$ICU_INCS -Wno-write-strings) PHP_ADD_BUILD_DIR($ext_builddir/collator) PHP_ADD_BUILD_DIR($ext_builddir/common) PHP_ADD_BUILD_DIR($ext_builddir/formatter) @@ -77,6 +84,8 @@ if test "$PHP_INTL" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/grapheme) PHP_ADD_BUILD_DIR($ext_builddir/resourcebundle) PHP_ADD_BUILD_DIR($ext_builddir/transliterator) + PHP_ADD_BUILD_DIR($ext_builddir/timezone) + PHP_ADD_BUILD_DIR($ext_builddir/calendar) PHP_ADD_BUILD_DIR($ext_builddir/idn) PHP_ADD_BUILD_DIR($ext_builddir/spoofchecker) fi diff --git a/ext/intl/config.w32 b/ext/intl/config.w32 index 437fedb7d3..ce12d9d342 100755 --- a/ext/intl/config.w32 +++ b/ext/intl/config.w32 @@ -7,7 +7,7 @@ if (PHP_INTL != "no") { if (CHECK_LIB("icuuc.lib", "intl", PHP_INTL) && CHECK_HEADER_ADD_INCLUDE("unicode/utf.h", "CFLAGS_INTL")) { // always build as shared - zend_strtod.c/ICU type conflict - EXTENSION("intl", "php_intl.c intl_convert.c intl_error.c ", true, + EXTENSION("intl", "php_intl.c intl_convert.c intl_convertcpp.cpp intl_error.c ", true, "/I \"" + configure_module_dirname + "\""); ADD_SOURCES(configure_module_dirname + "/collator", "\ collator.c \ @@ -23,6 +23,7 @@ if (PHP_INTL != "no") { ", "intl"); ADD_SOURCES(configure_module_dirname + "/common", "\ common_error.c \ + common_enum.cpp \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/formatter", "\ formatter.c \ @@ -87,6 +88,18 @@ if (PHP_INTL != "no") { transliterator_class.c \ transliterator_methods.c", "intl"); + + ADD_SOURCES(configure_module_dirname + "/timezone", "\ + timezone_class.cpp \ + timezone_methods.cpp", + "intl"); + + ADD_SOURCES(configure_module_dirname + "/calendar", "\ + calendar_methods.cpp \ + gregoriancalendar_methods.cpp \ + calendar_class.cpp", + "intl"); + ADD_FLAG("LIBS_INTL", "icudt.lib icuin.lib icuio.lib icule.lib iculx.lib"); AC_DEFINE("HAVE_INTL", 1, "Internationalization support enabled"); } else { diff --git a/ext/intl/intl_convertcpp.cpp b/ext/intl/intl_convertcpp.cpp new file mode 100644 index 0000000000..84988ef647 --- /dev/null +++ b/ext/intl/intl_convertcpp.cpp @@ -0,0 +1,80 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#include "intl_convertcpp.h" +#include <unicode/ustring.h> +extern "C" { +#include <php.h> +} + +/* {{{ intl_stringFromChar */ +int intl_stringFromChar(UnicodeString &ret, char *str, int32_t str_len, UErrorCode *status) +{ + //the number of UTF-16 code units is not larger than that of UTF-8 code + //units, + 1 for the terminator + int32_t capacity = str_len + 1; + + //no check necessary -- if NULL will fail ahead + UChar *utf16 = ret.getBuffer(capacity); + int32_t utf16_len = 0; + *status = U_ZERO_ERROR; + u_strFromUTF8WithSub(utf16, ret.getCapacity(), &utf16_len, + str, str_len, U_SENTINEL /* no substitution */, NULL, + status); + ret.releaseBuffer(utf16_len); + if (U_FAILURE(*status)) { + ret.setToBogus(); + return FAILURE; + } + return SUCCESS; +} +/* }}} */ + +/* {{{ intl_charFromString */ +int intl_charFromString(const UnicodeString &from, char **res, int *res_len, UErrorCode *status) +{ + //the number of UTF-8 code units is not larger than that of UTF-16 code + //units * 3 + 1 for the terminator + int32_t capacity = from.length() * 3 + 1; + + if (from.isEmpty()) { + *res = (char*)emalloc(1); + **res = '\0'; + *res_len = 0; + return SUCCESS; + } + + *res = (char*)emalloc(capacity); + *res_len = 0; //tbd + + const UChar *utf16buf = from.getBuffer(); + int32_t actual_len; + u_strToUTF8WithSub(*res, capacity - 1, &actual_len, utf16buf, from.length(), + U_SENTINEL, NULL, status); + + if (U_FAILURE(*status)) { + efree(*res); + *res = NULL; + return FAILURE; + } + (*res)[actual_len] = '\0'; + *res_len = (int)actual_len; + + return SUCCESS; +} +/* }}} */ diff --git a/ext/intl/intl_convertcpp.h b/ext/intl/intl_convertcpp.h new file mode 100644 index 0000000000..89d4209dd3 --- /dev/null +++ b/ext/intl/intl_convertcpp.h @@ -0,0 +1,32 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef INTL_CONVERTCPP_H +#define INTL_CONVERTCPP_H + +#ifndef __cplusplus +#error Should be included only in C++ Files +#endif + +#include <unicode/unistr.h> + +int intl_stringFromChar(UnicodeString &ret, char *str, int32_t str_len, UErrorCode *status); + +int intl_charFromString(const UnicodeString &from, char **res, int *res_len, UErrorCode *status); + +#endif /* INTL_CONVERTCPP_H */ diff --git a/ext/intl/locale/locale.h b/ext/intl/locale/locale.h index f3859c7a2a..0aaab4b5b5 100755 --- a/ext/intl/locale/locale.h +++ b/ext/intl/locale/locale.h @@ -22,6 +22,8 @@ #include <php.h> void locale_register_constants( INIT_FUNC_ARGS ); + +const char *intl_locale_get_default( TSRMLS_D ); #define OPTION_DEFAULT NULL #define LOC_LANG_TAG "language" diff --git a/ext/intl/locale/locale_methods.c b/ext/intl/locale/locale_methods.c index 39d162a510..8cc33cd74c 100755 --- a/ext/intl/locale/locale_methods.c +++ b/ext/intl/locale/locale_methods.c @@ -201,6 +201,14 @@ static int getSingletonPos(char* str) } /* }}} */ +const char *intl_locale_get_default( TSRMLS_D ) +{ + if( INTL_G(default_locale) == NULL ) { + return uloc_getDefault(); + } + return INTL_G(default_locale); +} + /* {{{ proto static string Locale::getDefault( ) Get default locale */ /* }}} */ @@ -208,10 +216,7 @@ static int getSingletonPos(char* str) Get default locale */ PHP_NAMED_FUNCTION(zif_locale_get_default) { - if( INTL_G(default_locale) == NULL ) { - INTL_G(default_locale) = pestrdup( uloc_getDefault(), 1); - } - RETURN_STRING( INTL_G(default_locale), TRUE ); + RETURN_STRING( intl_locale_get_default( TSRMLS_C ), TRUE ); } /* }}} */ diff --git a/ext/intl/php_intl.c b/ext/intl/php_intl.c index 514750f733..54b1e76073 100755 --- a/ext/intl/php_intl.c +++ b/ext/intl/php_intl.c @@ -68,6 +68,13 @@ #include "transliterator/transliterator_class.h" #include "transliterator/transliterator_methods.h" +#include "timezone/timezone_class.h" +#include "timezone/timezone_methods.h" + +#include "calendar/calendar_class.h" +#include "calendar/calendar_methods.h" +#include "calendar/gregoriancalendar_methods.h" + #include "idn/idn.h" #if U_ICU_VERSION_MAJOR_NUM > 3 && U_ICU_VERSION_MINOR_NUM >=2 @@ -79,6 +86,7 @@ #include "msgformat/msgformat.h" #include "common/common_error.h" +#include "common/common_enum.h" #include <unicode/uloc.h> #include <ext/standard/info.h> @@ -402,6 +410,176 @@ ZEND_BEGIN_ARG_INFO_EX( arginfo_transliterator_error, 0, 0, 1 ) ZEND_ARG_OBJ_INFO( 0, trans, Transliterator, 0 ) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_idarg_static, 0, 0, 1 ) + ZEND_ARG_INFO( 0, zoneId ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_create_enumeration, 0, 0, 0 ) + ZEND_ARG_INFO( 0, countryOrRawOffset ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_count_equivalent_ids, 0, 0, 1 ) + ZEND_ARG_INFO( 0, zoneId ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_create_time_zone_id_enumeration, 0, 0, 1 ) + ZEND_ARG_INFO( 0, zoneType ) + ZEND_ARG_INFO( 0, region ) + ZEND_ARG_INFO( 0, rawOffset ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_get_canonical_id, 0, 0, 1 ) + ZEND_ARG_INFO( 0, zoneId ) + ZEND_ARG_INFO( 1, isSystemID ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_get_equivalent_id, 0, 0, 2 ) + ZEND_ARG_INFO( 0, zoneId ) + ZEND_ARG_INFO( 0, index ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_get_offset, 0, 0, 5 ) + ZEND_ARG_OBJ_INFO( 0, timeZone, IntlTimeZone, 0 ) + ZEND_ARG_INFO( 0, date ) + ZEND_ARG_INFO( 0, local ) + ZEND_ARG_INFO( 1, rawOffset ) + ZEND_ARG_INFO( 1, dstOffset ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_has_same_rules, 0, 0, 1 ) + ZEND_ARG_OBJ_INFO( 0, timeZone, IntlTimeZone, 0 ) + ZEND_ARG_OBJ_INFO( 0, otherTimeZone, IntlTimeZone, 0 ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_get_display_name, 0, 0, 1 ) + ZEND_ARG_OBJ_INFO( 0, timeZone, IntlTimeZone, 0 ) + ZEND_ARG_INFO( 0, isDaylight ) + ZEND_ARG_INFO( 0, style ) + ZEND_ARG_INFO( 0, locale ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_only_tz, 0, 0, 1 ) + ZEND_ARG_OBJ_INFO( 0, timeZone, IntlTimeZone, 0 ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( arginfo_tz_void, 0, 0, 0 ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_create_instance, 0, 0, 0 ) + ZEND_ARG_INFO( 0, timeZone ) + ZEND_ARG_INFO( 0, locale ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_only_cal, 0, 0, 1 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_void, 0, 0, 0 ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_field, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, field ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_dow, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, dayOfWeek ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_other_cal, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_OBJ_INFO( 0, otherCalendar, IntlCalendar, 0 ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_date, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, date ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_date_optional, 0, 0, 1 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, date ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_get_keyword_values_for_locale, 0, 0, 3) + ZEND_ARG_INFO( 0, key ) + ZEND_ARG_INFO( 0, locale ) + ZEND_ARG_INFO( 0, commonlyUsed ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_add, 0, 0, 3 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, field ) + ZEND_ARG_INFO( 0, amount ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_set_time_zone, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_OBJ_INFO( 0, timeZone, IntlTimeZone, 1 ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_set, 0, 0, 3 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, fieldOrYear ) + ZEND_ARG_INFO( 0, valueOrMonth ) + ZEND_ARG_INFO( 0, dayOfMonth ) + ZEND_ARG_INFO( 0, hour ) + ZEND_ARG_INFO( 0, minute ) + ZEND_ARG_INFO( 0, second ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_roll, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, field ) + ZEND_ARG_INFO( 0, amountOrUpOrDown ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_clear, 0, 0, 1 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, field ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_field_difference, 0, 0, 3 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, when ) + ZEND_ARG_INFO( 0, field ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_get_locale, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, localeType ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_set_lenient, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, isLenient ) +ZEND_END_ARG_INFO() + +/* Gregorian Calendar */ +ZEND_BEGIN_ARG_INFO_EX( ainfo_gregcal_create_instance, 0, 0, 0 ) + ZEND_ARG_INFO(0, timeZoneOrYear) + ZEND_ARG_INFO(0, localeOrMonth) + ZEND_ARG_INFO(0, dayOfMonth) + ZEND_ARG_INFO(0, hour) + ZEND_ARG_INFO(0, minute) + ZEND_ARG_INFO(0, second) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_gregcal_is_leap_year, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlGregorianCalendar, 0 ) + ZEND_ARG_INFO( 0, year ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_gregcal_only_gregcal, 0, 0, 1 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlGregorianCalendar, 0 ) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX( ainfo_gregcal_set_gregorian_change, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlGregorianCalendar, 0 ) + ZEND_ARG_INFO( 0, date ) +ZEND_END_ARG_INFO() + /* }}} */ /* {{{ intl_functions @@ -530,6 +708,71 @@ zend_function_entry intl_functions[] = { PHP_FE( transliterator_get_error_code, arginfo_transliterator_error ) PHP_FE( transliterator_get_error_message, arginfo_transliterator_error ) + /* TimeZone functions */ + PHP_FE( intltz_create_time_zone, arginfo_tz_idarg_static ) + PHP_FE( intltz_create_default, arginfo_tz_void ) + PHP_FE( intltz_get_id, arginfo_tz_only_tz ) + PHP_FE( intltz_get_gmt, arginfo_tz_void ) + PHP_FE( intltz_create_enumeration, arginfo_tz_create_enumeration ) + PHP_FE( intltz_count_equivalent_ids, arginfo_tz_idarg_static ) + PHP_FE( intltz_create_time_zone_id_enumeration, arginfo_tz_create_time_zone_id_enumeration ) + PHP_FE( intltz_get_canonical_id, arginfo_tz_get_canonical_id ) + PHP_FE( intltz_get_region, arginfo_tz_idarg_static ) + PHP_FE( intltz_get_tz_data_version, arginfo_tz_void ) + PHP_FE( intltz_get_equivalent_id, arginfo_tz_get_equivalent_id ) + PHP_FE( intltz_use_daylight_time, arginfo_tz_only_tz ) + PHP_FE( intltz_get_offset, arginfo_tz_get_offset ) + PHP_FE( intltz_get_raw_offset, arginfo_tz_only_tz ) + PHP_FE( intltz_has_same_rules, arginfo_tz_has_same_rules ) + PHP_FE( intltz_get_display_name, arginfo_tz_get_display_name ) + PHP_FE( intltz_get_dst_savings, arginfo_tz_only_tz ) + PHP_FE( intltz_get_error_code, arginfo_tz_only_tz ) + PHP_FE( intltz_get_error_message, arginfo_tz_only_tz ) + + PHP_FE( intlcal_create_instance, ainfo_cal_create_instance ) + PHP_FE( intlcal_get_keyword_values_for_locale, ainfo_cal_get_keyword_values_for_locale ) + PHP_FE( intlcal_get_now, ainfo_cal_void ) + PHP_FE( intlcal_get_available_locales, ainfo_cal_void ) + PHP_FE( intlcal_get, ainfo_cal_field ) + PHP_FE( intlcal_get_time, ainfo_cal_only_cal ) + PHP_FE( intlcal_set_time, ainfo_cal_date ) + PHP_FE( intlcal_add, ainfo_cal_add ) + PHP_FE( intlcal_set_time_zone, ainfo_cal_set_time_zone ) + PHP_FE( intlcal_after, ainfo_cal_other_cal ) + PHP_FE( intlcal_before, ainfo_cal_other_cal ) + PHP_FE( intlcal_set, ainfo_cal_set ) + PHP_FE( intlcal_roll, ainfo_cal_roll ) + PHP_FE( intlcal_clear, ainfo_cal_clear ) + PHP_FE( intlcal_field_difference, ainfo_cal_field_difference ) + PHP_FE( intlcal_get_actual_maximum, ainfo_cal_field ) + PHP_FE( intlcal_get_actual_minimum, ainfo_cal_field ) + PHP_FE( intlcal_get_day_of_week_type, ainfo_cal_dow ) + PHP_FE( intlcal_get_first_day_of_week, ainfo_cal_only_cal ) + PHP_FE( intlcal_get_greatest_minimum, ainfo_cal_field ) + PHP_FE( intlcal_get_least_maximum, ainfo_cal_field ) + PHP_FE( intlcal_get_locale, ainfo_cal_get_locale ) + PHP_FE( intlcal_get_maximum, ainfo_cal_field ) + PHP_FE( intlcal_get_minimal_days_in_first_week, ainfo_cal_only_cal ) + PHP_FE( intlcal_get_minimum, ainfo_cal_field ) + PHP_FE( intlcal_get_time_zone, ainfo_cal_only_cal ) + PHP_FE( intlcal_get_type, ainfo_cal_only_cal ) + PHP_FE( intlcal_get_weekend_transition, ainfo_cal_dow ) + PHP_FE( intlcal_in_daylight_time, ainfo_cal_only_cal ) + PHP_FE( intlcal_is_equivalent_to, ainfo_cal_other_cal ) + PHP_FE( intlcal_is_lenient, ainfo_cal_only_cal ) + PHP_FE( intlcal_is_set, ainfo_cal_field ) + PHP_FE( intlcal_is_weekend, ainfo_cal_date_optional ) + PHP_FE( intlcal_set_first_day_of_week, ainfo_cal_dow ) + PHP_FE( intlcal_set_lenient, ainfo_cal_set_lenient ) + PHP_FE( intlcal_equals, ainfo_cal_other_cal ) + PHP_FE( intlcal_get_error_code, ainfo_cal_only_cal ) + PHP_FE( intlcal_get_error_message, ainfo_cal_only_cal ) + + PHP_FE( intlgregcal_create_instance, ainfo_gregcal_create_instance ) + PHP_FE( intlgregcal_set_gregorian_change, ainfo_gregcal_set_gregorian_change ) + PHP_FE( intlgregcal_get_gregorian_change, ainfo_gregcal_only_gregcal ) + PHP_FE( intlgregcal_is_leap_year, ainfo_gregcal_is_leap_year ) + /* common functions */ PHP_FE( intl_get_error_code, intl_0_args ) PHP_FE( intl_get_error_message, intl_0_args ) @@ -640,6 +883,12 @@ PHP_MINIT_FUNCTION( intl ) /* Register Transliterator constants */ transliterator_register_constants( INIT_FUNC_ARGS_PASSTHRU ); + /* Register 'IntlTimeZone' PHP class */ + timezone_register_IntlTimeZone_class( TSRMLS_C ); + + /* Register 'IntlCalendar' PHP class */ + calendar_register_IntlCalendar_class( TSRMLS_C ); + /* Expose ICU error codes to PHP scripts. */ intl_expose_icu_error_codes( INIT_FUNC_ARGS_PASSTHRU ); @@ -657,6 +906,9 @@ PHP_MINIT_FUNCTION( intl ) /* Register 'IntlException' PHP class */ intl_register_IntlException_class( TSRMLS_C ); + /* Register 'IntlIterator' PHP class */ + intl_register_IntlIterator_class( TSRMLS_C ); + /* Global error handling. */ intl_error_init( NULL TSRMLS_CC ); diff --git a/ext/intl/tests/calendar_add_basic.phpt b/ext/intl/tests/calendar_add_basic.phpt new file mode 100644 index 0000000000..db51c282b9 --- /dev/null +++ b/ext/intl/tests/calendar_add_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +IntlCalendar::add() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$time = strtotime('2012-02-29 00:00:00 +0000'); +$time2 = strtotime('2012-03-01 05:06:07 +0000'); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->setTime($time * 1000); +$intlcal->add(IntlCalendar::FIELD_DAY_OF_MONTH, 1); +$intlcal->add(IntlCalendar::FIELD_HOUR, 5); +$intlcal->add(IntlCalendar::FIELD_MINUTE, 6); +intlcal_add($intlcal, IntlCalendar::FIELD_SECOND, 7); + +var_dump( + (float)$time2*1000, + $intlcal->getTime()); + +?> +==DONE== +--EXPECT-- +float(1330578367000) +float(1330578367000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_add_error.phpt b/ext/intl/tests/calendar_add_error.phpt new file mode 100644 index 0000000000..2fd10b7ff2 --- /dev/null +++ b/ext/intl/tests/calendar_add_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +IntlCalendar::add(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->add(1, 2, 3)); +var_dump($c->add(-1, 2)); +var_dump($c->add(1)); + +var_dump(intlcal_add($c, 1, 2, 3)); +var_dump(intlcal_add(1, 2, 3)); +--EXPECTF-- + +Warning: IntlCalendar::add() expects exactly 2 parameters, 3 given in %s on line %d + +Warning: IntlCalendar::add(): intlcal_add: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::add(): intlcal_add: invalid field in %s on line %d +bool(false) + +Warning: IntlCalendar::add() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::add(): intlcal_add: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_add() expects exactly 3 parameters, 4 given in %s on line %d + +Warning: intlcal_add(): intlcal_add: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_add() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_before_after_error.phpt b/ext/intl/tests/calendar_before_after_error.phpt new file mode 100644 index 0000000000..7a71712a4b --- /dev/null +++ b/ext/intl/tests/calendar_before_after_error.phpt @@ -0,0 +1,55 @@ +--TEST-- +IntlCalendar::before()/after(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +function eh($errno, $errstr) { +echo "error: $errno, $errstr\n"; +} +set_error_handler('eh'); + +var_dump($c->after()); +var_dump($c->before()); + +var_dump($c->after(1)); +var_dump($c->before(1)); + +var_dump($c->after($c, 1)); +var_dump($c->before($c, 1)); + +var_dump(intlcal_after($c)); +var_dump(intlcal_before($c)); +--EXPECT-- +error: 2, IntlCalendar::after() expects exactly 1 parameter, 0 given +error: 2, IntlCalendar::after(): intlcal_before/after: bad arguments +bool(false) +error: 2, IntlCalendar::before() expects exactly 1 parameter, 0 given +error: 2, IntlCalendar::before(): intlcal_before/after: bad arguments +bool(false) +error: 4096, Argument 1 passed to IntlCalendar::after() must be an instance of IntlCalendar, integer given +error: 2, IntlCalendar::after() expects parameter 1 to be IntlCalendar, integer given +error: 2, IntlCalendar::after(): intlcal_before/after: bad arguments +bool(false) +error: 4096, Argument 1 passed to IntlCalendar::before() must be an instance of IntlCalendar, integer given +error: 2, IntlCalendar::before() expects parameter 1 to be IntlCalendar, integer given +error: 2, IntlCalendar::before(): intlcal_before/after: bad arguments +bool(false) +error: 2, IntlCalendar::after() expects exactly 1 parameter, 2 given +error: 2, IntlCalendar::after(): intlcal_before/after: bad arguments +bool(false) +error: 2, IntlCalendar::before() expects exactly 1 parameter, 2 given +error: 2, IntlCalendar::before(): intlcal_before/after: bad arguments +bool(false) +error: 2, intlcal_after() expects exactly 2 parameters, 1 given +error: 2, intlcal_after(): intlcal_before/after: bad arguments +bool(false) +error: 2, intlcal_before() expects exactly 2 parameters, 1 given +error: 2, intlcal_before(): intlcal_before/after: bad arguments +bool(false) diff --git a/ext/intl/tests/calendar_clear_basic.phpt b/ext/intl/tests/calendar_clear_basic.phpt new file mode 100644 index 0000000000..f7e4371d92 --- /dev/null +++ b/ext/intl/tests/calendar_clear_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlCalendar::clear() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +var_dump($intlcal->clear()); +var_dump( + $intlcal->get(IntlCalendar::FIELD_YEAR), + $intlcal->get(IntlCalendar::FIELD_MONTH), + $intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH), + $intlcal->get(IntlCalendar::FIELD_HOUR), + $intlcal->get(IntlCalendar::FIELD_MINUTE), + $intlcal->get(IntlCalendar::FIELD_SECOND), + $intlcal->get(IntlCalendar::FIELD_MILLISECOND) +); + +$intlcal2 = IntlCalendar::createInstance('Europe/Amsterdam'); +intlcal_clear($intlcal2, null); +var_dump($intlcal2->getTime()); + +?> +==DONE== +--EXPECT-- +bool(true) +int(1970) +int(0) +int(1) +int(0) +int(0) +int(0) +int(0) +float(-3600000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_clear_error.phpt b/ext/intl/tests/calendar_clear_error.phpt new file mode 100644 index 0000000000..3ce942a1e5 --- /dev/null +++ b/ext/intl/tests/calendar_clear_error.phpt @@ -0,0 +1,29 @@ +--TEST-- +IntlCalendar::clear(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->clear(1, 2)); +var_dump($c->clear(-1)); + +var_dump(intlcal_clear($c, -1)); +var_dump(intlcal_clear(1, 2)); +--EXPECTF-- + +Warning: IntlCalendar::clear(): intlcal_clear: too many arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::clear(): intlcal_clear: invalid field in %s on line %d +bool(false) + +Warning: intlcal_clear(): intlcal_clear: invalid field in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_clear() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_clear_variation1.phpt b/ext/intl/tests/calendar_clear_variation1.phpt new file mode 100644 index 0000000000..46987d24e1 --- /dev/null +++ b/ext/intl/tests/calendar_clear_variation1.phpt @@ -0,0 +1,31 @@ +--TEST-- +IntlCalendar::clear() 1 arg variation +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->setTime(strtotime('2012-02-29 05:06:07 +0000') * 1000); +//print_R($intlcal); +var_dump($intlcal->isSet(IntlCalendar::FIELD_MONTH)); +var_dump($intlcal->clear(IntlCalendar::FIELD_MONTH)); +var_dump($intlcal->isSet(IntlCalendar::FIELD_MONTH)); +//print_R($intlcal); +var_dump( + $intlcal->getTime(), + strtotime('2012-01-29 05:06:07 +0000') * 1000. +); +?> +==DONE== +--EXPECT-- +bool(true) +bool(true) +bool(false) +float(1327813567000) +float(1327813567000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_createInstance_basic.phpt b/ext/intl/tests/calendar_createInstance_basic.phpt new file mode 100644 index 0000000000..3c40b98b42 --- /dev/null +++ b/ext/intl/tests/calendar_createInstance_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlCalendar::createInstance() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +date_default_timezone_set('Europe/Amsterdam'); + +$cal = IntlCalendar::createInstance(); +print_R($cal->getTimeZone()); +print_R($cal->getLocale(Locale::ACTUAL_LOCALE)); +echo "\n"; +print_R($cal->getType()); +echo "\n"; + +$timeMillis = $cal->getTime(); +$time = time(); + +var_dump(abs($timeMillis - $time * 1000) < 1000); + +?> +==DONE== + +--EXPECTF-- +IntlTimeZone Object +( + [valid] => 1 + [id] => Europe/Amsterdam + [rawOffset] => 3600000 + [currentOffset] => %d +) +nl +gregorian +bool(true) +==DONE== diff --git a/ext/intl/tests/calendar_createInstance_error.phpt b/ext/intl/tests/calendar_createInstance_error.phpt new file mode 100644 index 0000000000..bf655bee79 --- /dev/null +++ b/ext/intl/tests/calendar_createInstance_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +IntlCalendar::createInstance: bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +class X extends IntlTimeZone { +function __construct() {} +} + +var_dump(IntlCalendar::createInstance(1, 2, 3)); +var_dump(intlcal_create_instance(1, 2, 3)); +var_dump(intlcal_create_instance(new X, NULL)); +var_dump(intlcal_create_instance(NULL, array())); + +--EXPECTF-- + +Warning: IntlCalendar::createInstance() expects at most 2 parameters, 3 given in %s on line %d + +Warning: IntlCalendar::createInstance(): intlcal_create_calendar: bad arguments in %s on line %d +NULL + +Warning: intlcal_create_instance() expects at most 2 parameters, 3 given in %s on line %d + +Warning: intlcal_create_instance(): intlcal_create_calendar: bad arguments in %s on line %d +NULL + +Warning: intlcal_create_instance(): intlcal_create_instance: passed IntlTimeZone is not properly constructed in %s on line %d +NULL + +Warning: intlcal_create_instance() expects parameter 2 to be string, array given in %s on line %d + +Warning: intlcal_create_instance(): intlcal_create_calendar: bad arguments in %s on line %d +NULL diff --git a/ext/intl/tests/calendar_createInstance_variation1.phpt b/ext/intl/tests/calendar_createInstance_variation1.phpt new file mode 100644 index 0000000000..a68e199feb --- /dev/null +++ b/ext/intl/tests/calendar_createInstance_variation1.phpt @@ -0,0 +1,82 @@ +--TEST-- +IntlCalendar::createInstance() argument variations +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +date_default_timezone_set('Europe/Amsterdam'); + +$cal = intlcal_create_instance('Europe/Amsterdam'); +print_R($cal->getTimeZone()); +print_R($cal->getLocale(Locale::ACTUAL_LOCALE)); +echo "\n"; + +$cal = intlcal_create_instance('Europe/Lisbon', null); +print_R($cal->getTimeZone()); +print_R($cal->getLocale(Locale::ACTUAL_LOCALE)); +echo "\n"; + +$cal = intlcal_create_instance(IntlTimeZone::createTimeZone('Europe/Lisbon')); +print_R($cal->getTimeZone()); +print_R($cal->getLocale(Locale::ACTUAL_LOCALE)); +echo "\n"; + +$cal = intlcal_create_instance(null, "pt"); +print_R($cal->getTimeZone()); +print_R($cal->getLocale(Locale::ACTUAL_LOCALE)); +echo "\n"; + +$cal = intlcal_create_instance("Europe/Lisbon", "pt"); +print_R($cal->getTimeZone()); +print_R($cal->getLocale(Locale::ACTUAL_LOCALE)); +echo "\n"; + +?> +==DONE== +--EXPECTF-- +IntlTimeZone Object +( + [valid] => 1 + [id] => Europe/Amsterdam + [rawOffset] => 3600000 + [currentOffset] => %d +) +nl +IntlTimeZone Object +( + [valid] => 1 + [id] => Europe/Lisbon + [rawOffset] => 0 + [currentOffset] => %d +) +nl +IntlTimeZone Object +( + [valid] => 1 + [id] => Europe/Lisbon + [rawOffset] => 0 + [currentOffset] => %d +) +nl +IntlTimeZone Object +( + [valid] => 1 + [id] => Europe/Amsterdam + [rawOffset] => 3600000 + [currentOffset] => %d +) +pt +IntlTimeZone Object +( + [valid] => 1 + [id] => Europe/Lisbon + [rawOffset] => 0 + [currentOffset] => %d +) +pt +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_equals_before_after_basic.phpt b/ext/intl/tests/calendar_equals_before_after_basic.phpt new file mode 100644 index 0000000000..90a35e407c --- /dev/null +++ b/ext/intl/tests/calendar_equals_before_after_basic.phpt @@ -0,0 +1,57 @@ +--TEST-- +IntlCalendar::equals(), ::before() and ::after() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal1 = new IntlGregorianCalendar(2012, 1, 29, 16, 59, 59); +$intlcal2 = IntlCalendar::createInstance(null, '@calendar=japanese'); +$intlcal3 = new IntlGregorianCalendar(2012, 1, 29, 17, 00, 00); +$intlcal2->setTime($intlcal1->getTime()); + +var_dump($intlcal2->getType()); + +var_dump("1 eq 1", $intlcal1->equals($intlcal1)); + +var_dump("1 eq 2", $intlcal1->equals($intlcal2)); +var_dump("1 before 2", $intlcal1->before($intlcal2)); +var_dump("1 after 2", $intlcal1->after($intlcal2)); + +var_dump("1 eq 3", $intlcal1->equals($intlcal3)); +var_dump("1 before 3", $intlcal1->before($intlcal3)); +var_dump("1 after 3", $intlcal1->after($intlcal3)); + +var_dump("3 eq 2", intlcal_equals($intlcal3, $intlcal2)); +var_dump("3 before 2", intlcal_before($intlcal3, $intlcal2)); +var_dump("3 after 2", intlcal_after($intlcal3, $intlcal2)); + +?> +==DONE== +--EXPECT-- +string(8) "japanese" +string(6) "1 eq 1" +bool(true) +string(6) "1 eq 2" +bool(true) +string(10) "1 before 2" +bool(false) +string(9) "1 after 2" +bool(false) +string(6) "1 eq 3" +bool(false) +string(10) "1 before 3" +bool(true) +string(9) "1 after 3" +bool(false) +string(6) "3 eq 2" +bool(false) +string(10) "3 before 2" +bool(false) +string(9) "3 after 2" +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_equals_error.phpt b/ext/intl/tests/calendar_equals_error.phpt new file mode 100644 index 0000000000..36f93a95d7 --- /dev/null +++ b/ext/intl/tests/calendar_equals_error.phpt @@ -0,0 +1,44 @@ +--TEST-- +IntlCalendar::equals(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +function eh($errno, $errstr) { +echo "error: $errno, $errstr\n"; +} +set_error_handler('eh'); + +var_dump($c->equals()); +var_dump($c->equals(new stdclass)); +var_dump($c->equals(1, 2)); + +var_dump(intlcal_equals($c, array())); +var_dump(intlcal_equals(1, $c)); + +--EXPECT-- +error: 2, IntlCalendar::equals() expects exactly 1 parameter, 0 given +error: 2, IntlCalendar::equals(): intlcal_equals: bad arguments +bool(false) +error: 4096, Argument 1 passed to IntlCalendar::equals() must be an instance of IntlCalendar, instance of stdClass given +error: 2, IntlCalendar::equals() expects parameter 1 to be IntlCalendar, object given +error: 2, IntlCalendar::equals(): intlcal_equals: bad arguments +bool(false) +error: 4096, Argument 1 passed to IntlCalendar::equals() must be an instance of IntlCalendar, integer given +error: 2, IntlCalendar::equals() expects exactly 1 parameter, 2 given +error: 2, IntlCalendar::equals(): intlcal_equals: bad arguments +bool(false) +error: 4096, Argument 2 passed to intlcal_equals() must be an instance of IntlCalendar, array given +error: 2, intlcal_equals() expects parameter 2 to be IntlCalendar, array given +error: 2, intlcal_equals(): intlcal_equals: bad arguments +bool(false) +error: 4096, Argument 1 passed to intlcal_equals() must be an instance of IntlCalendar, integer given +error: 2, intlcal_equals() expects parameter 1 to be IntlCalendar, integer given +error: 2, intlcal_equals(): intlcal_equals: bad arguments +bool(false) diff --git a/ext/intl/tests/calendar_fieldDifference_basic.phpt b/ext/intl/tests/calendar_fieldDifference_basic.phpt new file mode 100644 index 0000000000..fdcd7d6cdd --- /dev/null +++ b/ext/intl/tests/calendar_fieldDifference_basic.phpt @@ -0,0 +1,33 @@ +--TEST-- +IntlCalendar::fieldDifference() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->setTime(strtotime('2012-02-29 05:06:07 +0000') * 1000); +var_dump( + $intlcal->fieldDifference( + strtotime('2012-02-29 06:06:08 +0000') * 1000, + IntlCalendar::FIELD_SECOND), + $intlcal->get(IntlCalendar::FIELD_HOUR_OF_DAY)); + + +$intlcal->setTime(strtotime('2012-02-29 05:06:07 +0000') * 1000); +var_dump( + intlcal_field_difference( + $intlcal, + strtotime('2012-02-29 06:07:08 +0000') * 1000, + IntlCalendar::FIELD_MINUTE)); +?> +==DONE== +--EXPECT-- +int(3601) +int(6) +int(61) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_fieldDifference_error.phpt b/ext/intl/tests/calendar_fieldDifference_error.phpt new file mode 100644 index 0000000000..778fe24242 --- /dev/null +++ b/ext/intl/tests/calendar_fieldDifference_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlCalendar::fieldDifference(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->fieldDifference($c, 2, 3)); +var_dump($c->fieldDifference(INF, 2)); +var_dump($c->fieldDifference(1)); + +var_dump(intlcal_field_difference($c, 0, 1, 2)); +var_dump(intlcal_field_difference(1, 0, 1)); + +--EXPECTF-- + +Warning: IntlCalendar::fieldDifference() expects exactly 2 parameters, 3 given in %s on line %d + +Warning: IntlCalendar::fieldDifference(): intlcal_field_difference: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::fieldDifference(): intlcal_field_difference: Call to ICU method has failed in %s on line %d +bool(false) + +Warning: IntlCalendar::fieldDifference() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::fieldDifference(): intlcal_field_difference: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_field_difference() expects exactly 3 parameters, 4 given in %s on line %d + +Warning: intlcal_field_difference(): intlcal_field_difference: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_field_difference() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_getAvailableLocales_basic.phpt b/ext/intl/tests/calendar_getAvailableLocales_basic.phpt new file mode 100644 index 0000000000..5d5b79c020 --- /dev/null +++ b/ext/intl/tests/calendar_getAvailableLocales_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +IntlCalendar::getAvailableLocales() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$locales = IntlCalendar::getAvailableLocales(); +var_dump(count($locales) > 100); + +$locales = intlcal_get_available_locales(); +var_dump(in_array('pt', $locales)); + +?> +==DONE== +--EXPECT-- +bool(true) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getAvailableLocales_error.phpt b/ext/intl/tests/calendar_getAvailableLocales_error.phpt new file mode 100644 index 0000000000..e9edc468e5 --- /dev/null +++ b/ext/intl/tests/calendar_getAvailableLocales_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlCalendar::getAvailableLocales(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(intlcal_get_available_locales(1)); +var_dump(IntlCalendar::getAvailableLocales(2)); + +--EXPECTF-- + +Warning: intlcal_get_available_locales() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: intlcal_get_available_locales(): intlcal_get_available_locales: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getAvailableLocales() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getAvailableLocales(): intlcal_get_available_locales: bad arguments in %s on line %d +bool(false) diff --git a/ext/intl/tests/calendar_getDayOfWeekType_basic.phpt b/ext/intl/tests/calendar_getDayOfWeekType_basic.phpt new file mode 100644 index 0000000000..05dc2e4b00 --- /dev/null +++ b/ext/intl/tests/calendar_getDayOfWeekType_basic.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlCalendar::getDayOfWeekType() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->setTime(strtotime('2012-02-29 00:00:00 +0000') * 1000); +var_dump( + intlcal_get_day_of_week_type($intlcal, IntlCalendar::DOW_SUNDAY), + $intlcal->getDayOfWeekType(IntlCalendar::DOW_MONDAY), + $intlcal->getDayOfWeekType(IntlCalendar::DOW_TUESDAY), + $intlcal->getDayOfWeekType(IntlCalendar::DOW_FRIDAY), + $intlcal->getDayOfWeekType(IntlCalendar::DOW_SATURDAY) +); + +?> +==DONE== +--EXPECT-- +int(3) +int(0) +int(0) +int(0) +int(1) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getDayOfWeekType_error.phpt b/ext/intl/tests/calendar_getDayOfWeekType_error.phpt new file mode 100644 index 0000000000..29647c3300 --- /dev/null +++ b/ext/intl/tests/calendar_getDayOfWeekType_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlCalendar::getDayOfWeekOfType(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getDayOfWeekType(1, 2)); +var_dump($c->getDayOfWeekType(0)); +var_dump($c->getDayOfWeekType()); + +var_dump(intlcal_get_day_of_week_type($c, "foo")); +var_dump(intlcal_get_day_of_week_type(1, 1)); + +--EXPECTF-- + +Warning: IntlCalendar::getDayOfWeekType() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::getDayOfWeekType(): intlcal_get_day_of_week_type: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getDayOfWeekType(): intlcal_get_day_of_week_type: invalid day of week in %s on line %d +bool(false) + +Warning: IntlCalendar::getDayOfWeekType() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::getDayOfWeekType(): intlcal_get_day_of_week_type: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_get_day_of_week_type() expects parameter 2 to be long, string given in %s on line %d + +Warning: intlcal_get_day_of_week_type(): intlcal_get_day_of_week_type: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_day_of_week_type() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_getErrorCode_error.phpt b/ext/intl/tests/calendar_getErrorCode_error.phpt new file mode 100644 index 0000000000..d4b417cb83 --- /dev/null +++ b/ext/intl/tests/calendar_getErrorCode_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlCalendar::getErrorCode(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getErrorCode(array())); + +var_dump(intlcal_get_error_code(null)); + +--EXPECTF-- + +Warning: IntlCalendar::getErrorCode() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getErrorCode(): intlcal_get_error_code: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_error_code() must be an instance of IntlCalendar, null given in %s on line %d diff --git a/ext/intl/tests/calendar_getErrorCode_getErrorMessage_basic.phpt b/ext/intl/tests/calendar_getErrorCode_getErrorMessage_basic.phpt new file mode 100644 index 0000000000..7c56c000c1 --- /dev/null +++ b/ext/intl/tests/calendar_getErrorCode_getErrorMessage_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +IntlCalendar::getErrorCode(), ::getErrorMessage() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = new IntlGregorianCalendar(2012, 1, 29); +var_dump( + $intlcal->getErrorCode(), + intlcal_get_error_code($intlcal), + $intlcal->getErrorMessage(), + intlcal_get_error_message($intlcal) +); +$intlcal->add(IntlCalendar::FIELD_SECOND, 2147483647); +$intlcal->fieldDifference(-PHP_INT_MAX, IntlCalendar::FIELD_SECOND); + +var_dump( + $intlcal->getErrorCode(), + intlcal_get_error_code($intlcal), + $intlcal->getErrorMessage(), + intlcal_get_error_message($intlcal) +); +?> +==DONE== +--EXPECTF-- +int(0) +int(0) +string(12) "U_ZERO_ERROR" +string(12) "U_ZERO_ERROR" + +Warning: IntlCalendar::fieldDifference(): intlcal_field_difference: Call to ICU method has failed in %s on line %d +int(1) +int(1) +string(81) "intlcal_field_difference: Call to ICU method has failed: U_ILLEGAL_ARGUMENT_ERROR" +string(81) "intlcal_field_difference: Call to ICU method has failed: U_ILLEGAL_ARGUMENT_ERROR" +==DONE==
diff --git a/ext/intl/tests/calendar_getErrorMessage_error.phpt b/ext/intl/tests/calendar_getErrorMessage_error.phpt new file mode 100644 index 0000000000..500319e41c --- /dev/null +++ b/ext/intl/tests/calendar_getErrorMessage_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlCalendar::getErrorMessage(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getErrorMessage(array())); + +var_dump(intlcal_get_error_message(null)); + +--EXPECTF-- + +Warning: IntlCalendar::getErrorMessage() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getErrorMessage(): intlcal_get_error_message: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_error_message() must be an instance of IntlCalendar, null given in %s on line %d diff --git a/ext/intl/tests/calendar_getFirstDayOfWeek_basic.phpt b/ext/intl/tests/calendar_getFirstDayOfWeek_basic.phpt new file mode 100644 index 0000000000..82a0bc85cc --- /dev/null +++ b/ext/intl/tests/calendar_getFirstDayOfWeek_basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +IntlCalendar::getFirstDayOfWeek() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +var_dump($intlcal->getFirstDayOfWeek()); +var_dump(intlcal_get_first_day_of_week($intlcal)); +?> +==DONE== +--EXPECT-- +int(2) +int(2) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getFirstDayOfWeek_error.phpt b/ext/intl/tests/calendar_getFirstDayOfWeek_error.phpt new file mode 100644 index 0000000000..8c1a72fd07 --- /dev/null +++ b/ext/intl/tests/calendar_getFirstDayOfWeek_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlCalendar::getFirstDayOfWeek(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getFirstDayOfWeek(1)); + +var_dump(intlcal_get_first_day_of_week($c, 1)); +var_dump(intlcal_get_first_day_of_week(1)); + +--EXPECTF-- + +Warning: IntlCalendar::getFirstDayOfWeek() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getFirstDayOfWeek(): intlcal_get_first_day_of_week: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_get_first_day_of_week() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlcal_get_first_day_of_week(): intlcal_get_first_day_of_week: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_first_day_of_week() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_getKeywordValuesForLocale_basic.phpt b/ext/intl/tests/calendar_getKeywordValuesForLocale_basic.phpt new file mode 100644 index 0000000000..fbd40053ca --- /dev/null +++ b/ext/intl/tests/calendar_getKeywordValuesForLocale_basic.phpt @@ -0,0 +1,34 @@ +--TEST-- +IntlCalendar::getKeywordValuesForLocale() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +print_r( +iterator_to_array( +IntlCalendar::getKeywordValuesForLocale('calendar', 'pt', true) +)); +echo "\n"; + +$var = iterator_to_array( +intlcal_get_keyword_values_for_locale('calendar', 'pt', false) +); +var_dump(count($var) > 8); +var_dump(in_array('japanese', $var)); + +?> +==DONE== +--EXPECT-- +Array +( + [0] => gregorian +) + +bool(true) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getKeywordValuesForLocale_error.phpt b/ext/intl/tests/calendar_getKeywordValuesForLocale_error.phpt new file mode 100644 index 0000000000..c95e6097d2 --- /dev/null +++ b/ext/intl/tests/calendar_getKeywordValuesForLocale_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlCalendar::getKeywordValuesForLocale(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(intlcal_get_keyword_values_for_locale(1, 2)); +var_dump(IntlCalendar::getKeywordValuesForLocale(1, 2, array())); + +--EXPECTF-- + +Warning: intlcal_get_keyword_values_for_locale() expects exactly 3 parameters, 2 given in %s on line %d + +Warning: intlcal_get_keyword_values_for_locale(): intlcal_get_keyword_values_for_locale: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getKeywordValuesForLocale() expects parameter 3 to be boolean, array given in %s on line %d + +Warning: IntlCalendar::getKeywordValuesForLocale(): intlcal_get_keyword_values_for_locale: bad arguments in %s on line %d +bool(false) diff --git a/ext/intl/tests/calendar_getLocale_basic.phpt b/ext/intl/tests/calendar_getLocale_basic.phpt new file mode 100644 index 0000000000..55937d6aa9 --- /dev/null +++ b/ext/intl/tests/calendar_getLocale_basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +IntlCalendar::getLocale() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +var_dump($intlcal->getLocale(Locale::ACTUAL_LOCALE)); +var_dump(intlcal_get_locale($intlcal, Locale::VALID_LOCALE)); +?> +==DONE== +--EXPECT-- +string(2) "nl" +string(5) "nl_NL" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getLocale_error.phpt b/ext/intl/tests/calendar_getLocale_error.phpt new file mode 100644 index 0000000000..d50099b498 --- /dev/null +++ b/ext/intl/tests/calendar_getLocale_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlCalendar::getLocale(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getLocale()); +var_dump($c->getLocale(2)); +var_dump($c->getLocale(2, 3)); + +var_dump(intlcal_get_locale($c)); +var_dump(intlcal_get_locale(1)); + +--EXPECTF-- + +Warning: IntlCalendar::getLocale() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::getLocale(): intlcal_get_locale: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getLocale(): intlcal_get_locale: invalid locale type in %s on line %d +bool(false) + +Warning: IntlCalendar::getLocale() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::getLocale(): intlcal_get_locale: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_get_locale() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: intlcal_get_locale(): intlcal_get_locale: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_locale() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_getMinimalDaysInFirstWeek_basic.phpt b/ext/intl/tests/calendar_getMinimalDaysInFirstWeek_basic.phpt new file mode 100644 index 0000000000..d345b7cd2b --- /dev/null +++ b/ext/intl/tests/calendar_getMinimalDaysInFirstWeek_basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +IntlCalendar::getMinimalDaysInFirstWeek() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +var_dump($intlcal->getMinimalDaysInFirstWeek()); +var_dump(intlcal_get_minimal_days_in_first_week($intlcal)); +?> +==DONE== +--EXPECT-- +int(4) +int(4) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getMinimalDaysInFirstWeek_error.phpt b/ext/intl/tests/calendar_getMinimalDaysInFirstWeek_error.phpt new file mode 100644 index 0000000000..b974fe71ba --- /dev/null +++ b/ext/intl/tests/calendar_getMinimalDaysInFirstWeek_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlCalendar::getMinimalDaysInFirstWeek(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getMinimalDaysInFirstWeek(1)); + +var_dump(intlcal_get_minimal_days_in_first_week($c, 1)); +var_dump(intlcal_get_minimal_days_in_first_week(1)); + +--EXPECTF-- + +Warning: IntlCalendar::getMinimalDaysInFirstWeek() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getMinimalDaysInFirstWeek(): intlcal_get_minimal_days_in_first_week: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_get_minimal_days_in_first_week() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlcal_get_minimal_days_in_first_week(): intlcal_get_minimal_days_in_first_week: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_minimal_days_in_first_week() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_getNow_basic.phpt b/ext/intl/tests/calendar_getNow_basic.phpt new file mode 100644 index 0000000000..18325dfa60 --- /dev/null +++ b/ext/intl/tests/calendar_getNow_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +IntlCalendar::getNow() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$now = IntlCalendar::getNow(); +$proc_now = intlcal_get_now(); +$time = time(); +var_dump(abs($now - $proc_now) < 500); +var_dump(abs($time * 1000 - $proc_now) < 1000); + +?> +==DONE== +--EXPECT-- +bool(true) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getNow_error.phpt b/ext/intl/tests/calendar_getNow_error.phpt new file mode 100644 index 0000000000..31991bb591 --- /dev/null +++ b/ext/intl/tests/calendar_getNow_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlCalendar::getNow(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(intlcal_get_now(1)); +var_dump(IntlCalendar::getNow(2)); + +--EXPECTF-- + +Warning: intlcal_get_now() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: intlcal_get_now(): intlcal_get_now: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getNow() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getNow(): intlcal_get_now: bad arguments in %s on line %d +bool(false) diff --git a/ext/intl/tests/calendar_getTimeZone_basic.phpt b/ext/intl/tests/calendar_getTimeZone_basic.phpt new file mode 100644 index 0000000000..3a1edb5c6b --- /dev/null +++ b/ext/intl/tests/calendar_getTimeZone_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +IntlCalendar::getTimeZone() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('GMT+00:01'); +print_r($intlcal->getTimeZone()); +print_r(intlcal_get_time_zone($intlcal)); +?> +==DONE== +--EXPECT-- +IntlTimeZone Object +( + [valid] => 1 + [id] => GMT+00:01 + [rawOffset] => 60000 + [currentOffset] => 60000 +) +IntlTimeZone Object +( + [valid] => 1 + [id] => GMT+00:01 + [rawOffset] => 60000 + [currentOffset] => 60000 +) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getTimeZone_error.phpt b/ext/intl/tests/calendar_getTimeZone_error.phpt new file mode 100644 index 0000000000..2564a57c77 --- /dev/null +++ b/ext/intl/tests/calendar_getTimeZone_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlCalendar::getTimeZone(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getTimeZone(1)); + +var_dump(intlcal_get_time_zone($c, 1)); +var_dump(intlcal_get_time_zone(1)); + +--EXPECTF-- + +Warning: IntlCalendar::getTimeZone() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getTimeZone(): intlcal_get_time_zone: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_get_time_zone() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlcal_get_time_zone(): intlcal_get_time_zone: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_time_zone() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_getTime_basic.phpt b/ext/intl/tests/calendar_getTime_basic.phpt new file mode 100644 index 0000000000..9ac652172f --- /dev/null +++ b/ext/intl/tests/calendar_getTime_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +IntlCalendar::getTime() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->clear(); +$intlcal->set(IntlCalendar::FIELD_YEAR, 2012); +$intlcal->set(IntlCalendar::FIELD_MONTH, 1 /* Feb */); +$intlcal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 29); + +$time = strtotime('2012-02-29 00:00:00 +0000'); + +var_dump((float)$time*1000, $intlcal->getTime()); + +?> +==DONE== +--EXPECT-- +float(1330473600000) +float(1330473600000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getTime_error.phpt b/ext/intl/tests/calendar_getTime_error.phpt new file mode 100644 index 0000000000..a7a13080f7 --- /dev/null +++ b/ext/intl/tests/calendar_getTime_error.phpt @@ -0,0 +1,29 @@ +--TEST-- +IntlCalendar::getTime(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getTime(1)); + +var_dump(intlcal_get_time($c, 1)); +var_dump(intlcal_get_time(1)); +--EXPECTF-- + +Warning: IntlCalendar::getTime() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getTime(): intlcal_get_time: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_get_time() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlcal_get_time(): intlcal_get_time: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_time() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_getType_basic.phpt b/ext/intl/tests/calendar_getType_basic.phpt new file mode 100644 index 0000000000..d3026868a8 --- /dev/null +++ b/ext/intl/tests/calendar_getType_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +IntlCalendar::getType() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance(); +VAR_DUMP($intlcal->getType()); +$intlcal = IntlCalendar::createInstance(null, "nl_NL@calendar=hebrew"); +VAR_DUMP(intlcal_get_type($intlcal)); +?> +==DONE== +--EXPECT-- +string(9) "gregorian" +string(6) "hebrew" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getType_error.phpt b/ext/intl/tests/calendar_getType_error.phpt new file mode 100644 index 0000000000..ec81cc1dcc --- /dev/null +++ b/ext/intl/tests/calendar_getType_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlCalendar::getType(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getType(1)); + +var_dump(intlcal_get_type($c, 1)); +var_dump(intlcal_get_type(1)); + +--EXPECTF-- + +Warning: IntlCalendar::getType() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getType(): intlcal_get_type: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_get_type() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlcal_get_type(): intlcal_get_type: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_type() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_getWeekendTransition_basic.phpt b/ext/intl/tests/calendar_getWeekendTransition_basic.phpt new file mode 100644 index 0000000000..ea8372d7df --- /dev/null +++ b/ext/intl/tests/calendar_getWeekendTransition_basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +IntlCalendar::getWeekendTransition() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance(); +var_dump($intlcal->getWeekendTransition(IntlCalendar::DOW_SUNDAY)); +var_dump(intlcal_get_weekend_transition($intlcal, IntlCalendar::DOW_SUNDAY)); +?> +==DONE== +--EXPECT-- +int(86400000) +int(86400000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getWeekendTransition_error.phpt b/ext/intl/tests/calendar_getWeekendTransition_error.phpt new file mode 100644 index 0000000000..dbae310830 --- /dev/null +++ b/ext/intl/tests/calendar_getWeekendTransition_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlCalendar::getWeekendTransition(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getWeekendTransition()); +var_dump($c->getWeekendTransition(1, 2)); +var_dump($c->getWeekendTransition(0)); + +var_dump(intlcal_get_weekend_transition($c)); +var_dump(intlcal_get_weekend_transition(1, 1)); + +--EXPECTF-- + +Warning: IntlCalendar::getWeekendTransition() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::getWeekendTransition(): intlcal_get_weekend_transition: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getWeekendTransition() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::getWeekendTransition(): intlcal_get_weekend_transition: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getWeekendTransition(): intlcal_get_weekend_transition: invalid day of week in %s on line %d +bool(false) + +Warning: intlcal_get_weekend_transition() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: intlcal_get_weekend_transition(): intlcal_get_weekend_transition: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_weekend_transition() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_getXMaximum_basic.phpt b/ext/intl/tests/calendar_getXMaximum_basic.phpt new file mode 100644 index 0000000000..10bd570ba3 --- /dev/null +++ b/ext/intl/tests/calendar_getXMaximum_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +IntlCalendar::getMaximum(), ::getActualMaximum(), ::getLeastMaximum() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->setTime(strtotime('2012-02-29 05:06:07 +0000') * 1000); +var_dump( + $intlcal->getLeastMaximum(IntlCalendar::FIELD_DAY_OF_MONTH), + intlcal_get_least_maximum($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH), + $intlcal->getActualMaximum(IntlCalendar::FIELD_DAY_OF_MONTH), + intlcal_get_actual_maximum($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH), + $intlcal->getMaximum(IntlCalendar::FIELD_DAY_OF_MONTH), + intlcal_get_maximum($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH) +); + +?> +==DONE== +--EXPECT-- +int(28) +int(28) +int(29) +int(29) +int(31) +int(31) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_getXMinimum_basic.phpt b/ext/intl/tests/calendar_getXMinimum_basic.phpt new file mode 100644 index 0000000000..14b623ab41 --- /dev/null +++ b/ext/intl/tests/calendar_getXMinimum_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +IntlCalendar::getMinimum(), ::getActualMinimum(), ::getGreatestMinimum() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->setTime(strtotime('2012-02-29 05:06:07 +0000') * 1000); +var_dump( + $intlcal->getGreatestMinimum(IntlCalendar::FIELD_DAY_OF_MONTH), + intlcal_get_greatest_minimum($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH), + $intlcal->getActualMinimum(IntlCalendar::FIELD_DAY_OF_MONTH), + intlcal_get_actual_minimum($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH), + $intlcal->getMinimum(IntlCalendar::FIELD_DAY_OF_MONTH), + intlcal_get_minimum($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH) +); + +?> +==DONE== +--EXPECT-- +int(1) +int(1) +int(1) +int(1) +int(1) +int(1) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_get_Least_Greatest_Minimum_Maximum_error.phpt b/ext/intl/tests/calendar_get_Least_Greatest_Minimum_Maximum_error.phpt new file mode 100644 index 0000000000..3edb6604f5 --- /dev/null +++ b/ext/intl/tests/calendar_get_Least_Greatest_Minimum_Maximum_error.phpt @@ -0,0 +1,98 @@ +--TEST-- +IntlCalendar::get/Least/Greatest/Minimum/Maximum(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getLeastMaximum()); +var_dump($c->getMaximum()); +var_dump($c->getGreatestMinimum()); +var_dump($c->getMinimum()); + +var_dump($c->getLeastMaximum(-1)); +var_dump($c->getMaximum(-1)); +var_dump($c->getGreatestMinimum(-1)); +var_dump($c->getMinimum(-1)); + +var_dump(intlcal_get_least_maximum($c, -1)); +var_dump(intlcal_get_maximum($c, -1)); +var_dump(intlcal_get_greatest_minimum($c, -1)); +var_dump(intlcal_get_minimum($c, -1)); + +function eh($errno, $errstr) { +echo "error: $errno, $errstr\n"; +} +set_error_handler('eh'); + +var_dump(intlcal_get_least_maximum(1, 1)); +var_dump(intlcal_get_maximum(1, 1)); +var_dump(intlcal_get_greatest_minimum(1, -1)); +var_dump(intlcal_get_minimum(1, -1)); + +--EXPECTF-- + +Warning: IntlCalendar::getLeastMaximum() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::getLeastMaximum(): intlcal_get_least_maximum: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getMaximum() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::getMaximum(): intlcal_get_maximum: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getGreatestMinimum() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::getGreatestMinimum(): intlcal_get_greatest_minimum: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getMinimum() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::getMinimum(): intlcal_get_minimum: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getLeastMaximum(): intlcal_get_least_maximum: invalid field in %s on line %d +bool(false) + +Warning: IntlCalendar::getMaximum(): intlcal_get_maximum: invalid field in %s on line %d +bool(false) + +Warning: IntlCalendar::getGreatestMinimum(): intlcal_get_greatest_minimum: invalid field in %s on line %d +bool(false) + +Warning: IntlCalendar::getMinimum(): intlcal_get_minimum: invalid field in %s on line %d +bool(false) + +Warning: intlcal_get_least_maximum(): intlcal_get_least_maximum: invalid field in %s on line %d +bool(false) + +Warning: intlcal_get_maximum(): intlcal_get_maximum: invalid field in %s on line %d +bool(false) + +Warning: intlcal_get_greatest_minimum(): intlcal_get_greatest_minimum: invalid field in %s on line %d +bool(false) + +Warning: intlcal_get_minimum(): intlcal_get_minimum: invalid field in %s on line %d +bool(false) +error: 4096, Argument 1 passed to intlcal_get_least_maximum() must be an instance of IntlCalendar, integer given +error: 2, intlcal_get_least_maximum() expects parameter 1 to be IntlCalendar, integer given +error: 2, intlcal_get_least_maximum(): intlcal_get_least_maximum: bad arguments +bool(false) +error: 4096, Argument 1 passed to intlcal_get_maximum() must be an instance of IntlCalendar, integer given +error: 2, intlcal_get_maximum() expects parameter 1 to be IntlCalendar, integer given +error: 2, intlcal_get_maximum(): intlcal_get_maximum: bad arguments +bool(false) +error: 4096, Argument 1 passed to intlcal_get_greatest_minimum() must be an instance of IntlCalendar, integer given +error: 2, intlcal_get_greatest_minimum() expects parameter 1 to be IntlCalendar, integer given +error: 2, intlcal_get_greatest_minimum(): intlcal_get_greatest_minimum: bad arguments +bool(false) +error: 4096, Argument 1 passed to intlcal_get_minimum() must be an instance of IntlCalendar, integer given +error: 2, intlcal_get_minimum() expects parameter 1 to be IntlCalendar, integer given +error: 2, intlcal_get_minimum(): intlcal_get_minimum: bad arguments +bool(false) diff --git a/ext/intl/tests/calendar_get_basic.phpt b/ext/intl/tests/calendar_get_basic.phpt new file mode 100644 index 0000000000..c617639610 --- /dev/null +++ b/ext/intl/tests/calendar_get_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +IntlCalendar::get() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 4); + +var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH)); +var_dump(intlcal_get($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH)); + +?> +==DONE== +--EXPECT-- +int(4) +int(4) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error.phpt b/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error.phpt new file mode 100644 index 0000000000..79520d5edf --- /dev/null +++ b/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error.phpt @@ -0,0 +1,82 @@ +--TEST-- +IntlCalendar::get/getActualMaximum/getActualMinimum(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->get()); +var_dump($c->getActualMaximum()); +var_dump($c->getActualMinimum()); + +var_dump($c->get(-1)); +var_dump($c->getActualMaximum(-1)); +var_dump($c->getActualMinimum(-1)); + +var_dump($c->get("s")); +var_dump($c->getActualMaximum("s")); +var_dump($c->getActualMinimum("s")); + +var_dump($c->get(1, 2)); +var_dump($c->getActualMaximum(1, 2)); +var_dump($c->getActualMinimum(1, 2)); +--EXPECTF-- + +Warning: IntlCalendar::get() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::get(): intlcal_get: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getActualMaximum() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::getActualMaximum(): intlcal_get_actual_maximum: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getActualMinimum() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::getActualMinimum(): intlcal_get_actual_minimum: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::get(): intlcal_get: invalid field in %s on line %d +bool(false) + +Warning: IntlCalendar::getActualMaximum(): intlcal_get_actual_maximum: invalid field in %s on line %d +bool(false) + +Warning: IntlCalendar::getActualMinimum(): intlcal_get_actual_minimum: invalid field in %s on line %d +bool(false) + +Warning: IntlCalendar::get() expects parameter 1 to be long, string given in %s on line %d + +Warning: IntlCalendar::get(): intlcal_get: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getActualMaximum() expects parameter 1 to be long, string given in %s on line %d + +Warning: IntlCalendar::getActualMaximum(): intlcal_get_actual_maximum: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getActualMinimum() expects parameter 1 to be long, string given in %s on line %d + +Warning: IntlCalendar::getActualMinimum(): intlcal_get_actual_minimum: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::get() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::get(): intlcal_get: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getActualMaximum() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::getActualMaximum(): intlcal_get_actual_maximum: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getActualMinimum() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::getActualMinimum(): intlcal_get_actual_minimum: bad arguments in %s on line %d +bool(false) diff --git a/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error2.phpt b/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error2.phpt new file mode 100644 index 0000000000..e23ff22a30 --- /dev/null +++ b/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error2.phpt @@ -0,0 +1,69 @@ +--TEST-- +IntlCalendar::get/getActualMaximum/getActualMinimum(): bad arguments (procedural) +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +function eh($errno, $errstr) { +echo "error: $errno, $errstr\n"; +} +set_error_handler('eh'); + +var_dump(intlcal_get($c)); +var_dump(intlcal_get_actual_maximum($c)); +var_dump(intlcal_get_actual_minimum($c)); + +var_dump(intlcal_get($c, -1)); +var_dump(intlcal_get_actual_maximum($c, -1)); +var_dump(intlcal_get_actual_minimum($c, -1)); + +var_dump(intlcal_get($c, "s")); +var_dump(intlcal_get_actual_maximum($c, "s")); +var_dump(intlcal_get_actual_minimum($c, "s")); + +var_dump(intlcal_get(1)); +var_dump(intlcal_get_actual_maximum(1)); +var_dump(intlcal_get_actual_minimum(1)); +--EXPECT-- +error: 2, intlcal_get() expects exactly 2 parameters, 1 given +error: 2, intlcal_get(): intlcal_get: bad arguments +bool(false) +error: 2, intlcal_get_actual_maximum() expects exactly 2 parameters, 1 given +error: 2, intlcal_get_actual_maximum(): intlcal_get_actual_maximum: bad arguments +bool(false) +error: 2, intlcal_get_actual_minimum() expects exactly 2 parameters, 1 given +error: 2, intlcal_get_actual_minimum(): intlcal_get_actual_minimum: bad arguments +bool(false) +error: 2, intlcal_get(): intlcal_get: invalid field +bool(false) +error: 2, intlcal_get_actual_maximum(): intlcal_get_actual_maximum: invalid field +bool(false) +error: 2, intlcal_get_actual_minimum(): intlcal_get_actual_minimum: invalid field +bool(false) +error: 2, intlcal_get() expects parameter 2 to be long, string given +error: 2, intlcal_get(): intlcal_get: bad arguments +bool(false) +error: 2, intlcal_get_actual_maximum() expects parameter 2 to be long, string given +error: 2, intlcal_get_actual_maximum(): intlcal_get_actual_maximum: bad arguments +bool(false) +error: 2, intlcal_get_actual_minimum() expects parameter 2 to be long, string given +error: 2, intlcal_get_actual_minimum(): intlcal_get_actual_minimum: bad arguments +bool(false) +error: 4096, Argument 1 passed to intlcal_get() must be an instance of IntlCalendar, integer given +error: 2, intlcal_get() expects exactly 2 parameters, 1 given +error: 2, intlcal_get(): intlcal_get: bad arguments +bool(false) +error: 4096, Argument 1 passed to intlcal_get_actual_maximum() must be an instance of IntlCalendar, integer given +error: 2, intlcal_get_actual_maximum() expects exactly 2 parameters, 1 given +error: 2, intlcal_get_actual_maximum(): intlcal_get_actual_maximum: bad arguments +bool(false) +error: 4096, Argument 1 passed to intlcal_get_actual_minimum() must be an instance of IntlCalendar, integer given +error: 2, intlcal_get_actual_minimum() expects exactly 2 parameters, 1 given +error: 2, intlcal_get_actual_minimum(): intlcal_get_actual_minimum: bad arguments +bool(false) diff --git a/ext/intl/tests/calendar_inDaylightTime_basic.phpt b/ext/intl/tests/calendar_inDaylightTime_basic.phpt new file mode 100644 index 0000000000..087ae26c98 --- /dev/null +++ b/ext/intl/tests/calendar_inDaylightTime_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +IntlCalendar::inDaylightTime() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('Europe/Amsterdam'); +$intlcal->setTime(strtotime('2012-01-01') * 1000); +var_dump($intlcal->inDaylightTime()); +$intlcal->setTime(strtotime('2012-04-01') * 1000); +var_dump(intlcal_in_daylight_time($intlcal)); +?> +==DONE== +--EXPECT-- +bool(false) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_inDaylightTime_error.phpt b/ext/intl/tests/calendar_inDaylightTime_error.phpt new file mode 100644 index 0000000000..e7249efa09 --- /dev/null +++ b/ext/intl/tests/calendar_inDaylightTime_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlCalendar::inDaylightTime(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->inDaylightTime(1)); + +var_dump(intlcal_in_daylight_time($c, 1)); +var_dump(intlcal_in_daylight_time(1)); + +--EXPECTF-- + +Warning: IntlCalendar::inDaylightTime() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::inDaylightTime(): intlcal_in_daylight_time: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_in_daylight_time() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlcal_in_daylight_time(): intlcal_in_daylight_time: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_in_daylight_time() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_isEquivalentTo_basic.phpt b/ext/intl/tests/calendar_isEquivalentTo_basic.phpt new file mode 100644 index 0000000000..f71fd8ad5b --- /dev/null +++ b/ext/intl/tests/calendar_isEquivalentTo_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlCalendar::isEquivalentTo() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal1 = IntlCalendar::createInstance('Europe/Amsterdam'); +$intlcal2 = IntlCalendar::createInstance('Europe/Lisbon'); +$intlcal3 = IntlCalendar::createInstance('Europe/Amsterdam', "nl_NL@calendar=islamic"); +$intlcal4 = IntlCalendar::createInstance('Europe/Amsterdam'); +$intlcal4->roll(IntlCalendar::FIELD_MONTH, true); + +var_dump( + "1 - 1", + $intlcal1->isEquivalentTo($intlcal1), + "1 - 2", + $intlcal1->isEquivalentTo($intlcal2), + "1 - 3", + $intlcal1->isEquivalentTo($intlcal3), + "1 - 4", + $intlcal1->isEquivalentTo($intlcal4) +); + +?> +==DONE== +--EXPECT-- +string(5) "1 - 1" +bool(true) +string(5) "1 - 2" +bool(false) +string(5) "1 - 3" +bool(false) +string(5) "1 - 4" +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_isEquivalentTo_error.phpt b/ext/intl/tests/calendar_isEquivalentTo_error.phpt new file mode 100644 index 0000000000..caff614fa2 --- /dev/null +++ b/ext/intl/tests/calendar_isEquivalentTo_error.phpt @@ -0,0 +1,48 @@ +--TEST-- +IntlCalendar::isEquivalentTo(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +function eh($errno, $errstr) { +echo "error: $errno, $errstr\n"; +} +set_error_handler('eh'); + +var_dump($c->isEquivalentTo(0)); +var_dump($c->isEquivalentTo($c, 1)); +var_dump($c->isEquivalentTo(1)); + +var_dump(intlcal_is_equivalent_to($c)); +var_dump(intlcal_is_equivalent_to($c, 1)); +var_dump(intlcal_is_equivalent_to(1, $c)); + +--EXPECT-- +error: 4096, Argument 1 passed to IntlCalendar::isEquivalentTo() must be an instance of IntlCalendar, integer given +error: 2, IntlCalendar::isEquivalentTo() expects parameter 1 to be IntlCalendar, integer given +error: 2, IntlCalendar::isEquivalentTo(): intlcal_is_equivalent_to: bad arguments +bool(false) +error: 2, IntlCalendar::isEquivalentTo() expects exactly 1 parameter, 2 given +error: 2, IntlCalendar::isEquivalentTo(): intlcal_is_equivalent_to: bad arguments +bool(false) +error: 4096, Argument 1 passed to IntlCalendar::isEquivalentTo() must be an instance of IntlCalendar, integer given +error: 2, IntlCalendar::isEquivalentTo() expects parameter 1 to be IntlCalendar, integer given +error: 2, IntlCalendar::isEquivalentTo(): intlcal_is_equivalent_to: bad arguments +bool(false) +error: 2, intlcal_is_equivalent_to() expects exactly 2 parameters, 1 given +error: 2, intlcal_is_equivalent_to(): intlcal_is_equivalent_to: bad arguments +bool(false) +error: 4096, Argument 2 passed to intlcal_is_equivalent_to() must be an instance of IntlCalendar, integer given +error: 2, intlcal_is_equivalent_to() expects parameter 2 to be IntlCalendar, integer given +error: 2, intlcal_is_equivalent_to(): intlcal_is_equivalent_to: bad arguments +bool(false) +error: 4096, Argument 1 passed to intlcal_is_equivalent_to() must be an instance of IntlCalendar, integer given +error: 2, intlcal_is_equivalent_to() expects parameter 1 to be IntlCalendar, integer given +error: 2, intlcal_is_equivalent_to(): intlcal_is_equivalent_to: bad arguments +bool(false) diff --git a/ext/intl/tests/calendar_isLenient_error.phpt b/ext/intl/tests/calendar_isLenient_error.phpt new file mode 100644 index 0000000000..72b082b15a --- /dev/null +++ b/ext/intl/tests/calendar_isLenient_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlCalendar::isLenient(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->isLenient(1)); + +var_dump(intlcal_is_lenient($c, 1)); +var_dump(intlcal_is_lenient(1)); + +--EXPECTF-- + +Warning: IntlCalendar::isLenient() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::isLenient(): intlcal_is_lenient: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_is_lenient() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlcal_is_lenient(): intlcal_is_lenient: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_is_lenient() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_isSet_basic.phpt b/ext/intl/tests/calendar_isSet_basic.phpt new file mode 100644 index 0000000000..8ef01448d5 --- /dev/null +++ b/ext/intl/tests/calendar_isSet_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlCalendar::isSet() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +var_dump($intlcal->isSet(IntlCalendar::FIELD_MINUTE)); +$intlcal->clear(IntlCalendar::FIELD_MINUTE); +var_dump($intlcal->isSet(IntlCalendar::FIELD_MINUTE)); +$intlcal->set(IntlCalendar::FIELD_MINUTE, 0); +var_dump(intlcal_is_set($intlcal, IntlCalendar::FIELD_MINUTE)); +?> +==DONE== +--EXPECT-- +bool(true) +bool(false) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_isSet_error.phpt b/ext/intl/tests/calendar_isSet_error.phpt new file mode 100644 index 0000000000..07d3885431 --- /dev/null +++ b/ext/intl/tests/calendar_isSet_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlCalendar::isSet(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->isSet()); +var_dump($c->isSet(1, 2)); +var_dump($c->isSet(-1)); + +var_dump(intlcal_is_set($c)); +var_dump(intlcal_is_set(1, 2)); + +--EXPECTF-- + +Warning: IntlCalendar::isSet() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::isSet(): intlcal_is_set: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::isSet() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::isSet(): intlcal_is_set: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::isSet(): intlcal_is_set: invalid field in %s on line %d +bool(false) + +Warning: intlcal_is_set() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: intlcal_is_set(): intlcal_is_set: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_is_set() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_isWeekend_basic.phpt b/ext/intl/tests/calendar_isWeekend_basic.phpt new file mode 100644 index 0000000000..c520aacdcc --- /dev/null +++ b/ext/intl/tests/calendar_isWeekend_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +IntlCalendar::isWeekend basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +var_dump($intlcal->isWeekend(strtotime('2012-02-29 12:00:00 +0000') * 1000)); +var_dump(intlcal_is_weekend($intlcal, strtotime('2012-02-29 12:00:00 +0000') * 1000)); +var_dump($intlcal->isWeekend(strtotime('2012-03-11 12:00:00 +0000') * 1000)); +?> +==DONE== +--EXPECT-- +bool(false) +bool(false) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_isWeekend_error.phpt b/ext/intl/tests/calendar_isWeekend_error.phpt new file mode 100644 index 0000000000..e4a4649e6d --- /dev/null +++ b/ext/intl/tests/calendar_isWeekend_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +IntlCalendar::isWeekend(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->isWeekend(1, 2)); +var_dump($c->isWeekend("jhhk")); + +var_dump(intlcal_is_weekend($c, "jj")); +var_dump(intlcal_is_weekend(1)); + +--EXPECTF-- + +Warning: IntlCalendar::isWeekend(): intlcal_is_weekend: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::isWeekend() expects parameter 1 to be double, string given in %s on line %d + +Warning: IntlCalendar::isWeekend(): intlcal_is_weekend: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_is_weekend() expects parameter 2 to be double, string given in %s on line %d + +Warning: intlcal_is_weekend(): intlcal_is_weekend: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_is_weekend() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_is_set_lenient_basic.phpt b/ext/intl/tests/calendar_is_set_lenient_basic.phpt new file mode 100644 index 0000000000..64f537f9bc --- /dev/null +++ b/ext/intl/tests/calendar_is_set_lenient_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +IntlCalendar::isLenient(), ::setLenient() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal1 = IntlCalendar::createInstance('UTC'); +var_dump($intlcal1->isLenient()); +var_dump(intlcal_is_lenient($intlcal1)); +var_dump($intlcal1->setLenient(false)); +var_dump($intlcal1->isLenient()); +var_dump(intlcal_set_lenient($intlcal1, true)); +var_dump($intlcal1->isLenient()); +?> +==DONE== +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(false) +bool(true) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_roll_basic.phpt b/ext/intl/tests/calendar_roll_basic.phpt new file mode 100644 index 0000000000..8f64d9ec42 --- /dev/null +++ b/ext/intl/tests/calendar_roll_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +IntlCalendar::roll() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = new IntlGregorianCalendar(2012, 1, 28); +var_dump($intlcal->roll(IntlCalendar::FIELD_DAY_OF_MONTH, 2)); +var_dump($intlcal->get(IntlCalendar::FIELD_MONTH)); //1 (Feb) +var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH)); //1 + +$intlcal = new IntlGregorianCalendar(2012, 1, 28); +var_dump(intlcal_roll($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH, 2)); +var_dump($intlcal->get(IntlCalendar::FIELD_MONTH)); //1 (Feb) +var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH)); //1 + + +?> +==DONE== +--EXPECT-- +bool(true) +int(1) +int(1) +bool(true) +int(1) +int(1) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_roll_error.phpt b/ext/intl/tests/calendar_roll_error.phpt new file mode 100644 index 0000000000..61c0436341 --- /dev/null +++ b/ext/intl/tests/calendar_roll_error.phpt @@ -0,0 +1,35 @@ +--TEST-- +IntlCalendar::roll(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->roll(1, 2, 3)); +var_dump($c->roll(-1, 2)); +var_dump($c->roll(1)); + +var_dump(intlcal_roll($c, 1, 2, 3)); +var_dump(intlcal_roll(1, 2, 3)); +--EXPECTF-- + +Warning: IntlCalendar::roll(): intlcal_set: too many arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::roll(): intlcal_roll: invalid field in %s on line %d +bool(false) + +Warning: IntlCalendar::roll() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::roll(): intlcal_roll: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_roll(): intlcal_set: too many arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_roll() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_roll_variation1.phpt b/ext/intl/tests/calendar_roll_variation1.phpt new file mode 100644 index 0000000000..e034165f99 --- /dev/null +++ b/ext/intl/tests/calendar_roll_variation1.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlCalendar::roll() bool argument variation +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = new IntlGregorianCalendar(2012, 1, 28); +var_dump($intlcal->roll(IntlCalendar::FIELD_DAY_OF_MONTH, true)); +var_dump($intlcal->get(IntlCalendar::FIELD_MONTH)); //1 (Feb) +var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH)); //29 + +var_dump(intlcal_roll($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH, false)); +var_dump($intlcal->get(IntlCalendar::FIELD_MONTH)); //1 (Feb) +var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH)); //28 + +?> +==DONE== +--EXPECT-- +bool(true) +int(1) +int(29) +bool(true) +int(1) +int(28) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_setFirstDayOfWeek_basic.phpt b/ext/intl/tests/calendar_setFirstDayOfWeek_basic.phpt new file mode 100644 index 0000000000..79b38104e4 --- /dev/null +++ b/ext/intl/tests/calendar_setFirstDayOfWeek_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +IntlCalendar::setFirstDayOfWeek() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +var_dump( + IntlCalendar::DOW_TUESDAY, + $intlcal->setFirstDayOfWeek(IntlCalendar::DOW_TUESDAY), + $intlcal->getFirstDayOfWeek(), + intlcal_set_first_day_of_week($intlcal, IntlCalendar::DOW_WEDNESDAY), + $intlcal->getFirstDayOfWeek() +); +?> +==DONE== +--EXPECT-- +int(3) +bool(true) +int(3) +bool(true) +int(4) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_setFirstDayOfWeek_error.phpt b/ext/intl/tests/calendar_setFirstDayOfWeek_error.phpt new file mode 100644 index 0000000000..b393492fbe --- /dev/null +++ b/ext/intl/tests/calendar_setFirstDayOfWeek_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +IntlCalendar::setFirstDayOfWeek(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->setFirstDayOfWeek()); +var_dump($c->setFirstDayOfWeek(1, 2)); +var_dump($c->setFirstDayOfWeek(0)); + +var_dump(intlcal_set_first_day_of_week($c, 0)); +var_dump(intlcal_set_first_day_of_week(1, 2)); + +--EXPECTF-- + +Warning: IntlCalendar::setFirstDayOfWeek() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::setFirstDayOfWeek(): intlcal_set_first_day_of_week: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setFirstDayOfWeek() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::setFirstDayOfWeek(): intlcal_set_first_day_of_week: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setFirstDayOfWeek(): intlcal_set_first_day_of_week: invalid day of week in %s on line %d +bool(false) + +Warning: intlcal_set_first_day_of_week(): intlcal_set_first_day_of_week: invalid day of week in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_set_first_day_of_week() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_setLenient_error.phpt b/ext/intl/tests/calendar_setLenient_error.phpt new file mode 100644 index 0000000000..65e921f137 --- /dev/null +++ b/ext/intl/tests/calendar_setLenient_error.phpt @@ -0,0 +1,42 @@ +--TEST-- +IntlCalendar::setLenient(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->setLenient()); +var_dump($c->setLenient(array())); +var_dump($c->setLenient(1, 2)); + +var_dump(intlcal_set_lenient($c, array())); +var_dump(intlcal_set_lenient(1, false)); + +--EXPECTF-- + +Warning: IntlCalendar::setLenient() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::setLenient(): intlcal_set_lenient: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setLenient() expects parameter 1 to be boolean, array given in %s on line %d + +Warning: IntlCalendar::setLenient(): intlcal_set_lenient: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setLenient() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::setLenient(): intlcal_set_lenient: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_set_lenient() expects parameter 2 to be boolean, array given in %s on line %d + +Warning: intlcal_set_lenient(): intlcal_set_lenient: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_set_lenient() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_setTimeZone_basic.phpt b/ext/intl/tests/calendar_setTimeZone_basic.phpt new file mode 100644 index 0000000000..0609509038 --- /dev/null +++ b/ext/intl/tests/calendar_setTimeZone_basic.phpt @@ -0,0 +1,37 @@ +--TEST-- +IntlCalendar::setTimeZone() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('Europe/Amsterdam'); +print_r($intlcal->getTimeZone()->getID()); +echo "\n"; +var_dump($intlcal->get(IntlCalendar::FIELD_ZONE_OFFSET)); + +$intlcal->setTimeZone(IntlTimeZone::getGMT()); +print_r($intlcal->getTimeZone()->getID()); +echo "\n"; +var_dump($intlcal->get(IntlCalendar::FIELD_ZONE_OFFSET)); + +intlcal_set_time_zone($intlcal, + IntlTimeZone::createTimeZone('GMT+05:30')); +print_r($intlcal->getTimeZone()->getID()); +echo "\n"; +var_dump($intlcal->get(IntlCalendar::FIELD_ZONE_OFFSET)); + +?> +==DONE== +--EXPECT-- +Europe/Amsterdam +int(3600000) +GMT +int(0) +GMT+05:30 +int(19800000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_setTimeZone_error.phpt b/ext/intl/tests/calendar_setTimeZone_error.phpt new file mode 100644 index 0000000000..924275c799 --- /dev/null +++ b/ext/intl/tests/calendar_setTimeZone_error.phpt @@ -0,0 +1,44 @@ +--TEST-- +IntlCalendar::setTimeZone(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +$gmt = IntlTimeZone::getGMT(); + +function eh($errno, $errstr) { +echo "error: $errno, $errstr\n"; +} +set_error_handler('eh'); + +var_dump($c->setTimeZone($gmt, 2)); +var_dump($c->setTimeZone(1)); +var_dump($c->setTimeZone()); + +var_dump(intlcal_set_time_zone($c, 1)); +var_dump(intlcal_set_time_zone(1, $gmt)); +--EXPECT-- +error: 2, IntlCalendar::setTimeZone() expects exactly 1 parameter, 2 given +error: 2, IntlCalendar::setTimeZone(): intlcal_set_time_zone: bad arguments +bool(false) +error: 4096, Argument 1 passed to IntlCalendar::setTimeZone() must be an instance of IntlTimeZone, integer given +error: 2, IntlCalendar::setTimeZone() expects parameter 1 to be IntlTimeZone, integer given +error: 2, IntlCalendar::setTimeZone(): intlcal_set_time_zone: bad arguments +bool(false) +error: 2, IntlCalendar::setTimeZone() expects exactly 1 parameter, 0 given +error: 2, IntlCalendar::setTimeZone(): intlcal_set_time_zone: bad arguments +bool(false) +error: 4096, Argument 2 passed to intlcal_set_time_zone() must be an instance of IntlTimeZone, integer given +error: 2, intlcal_set_time_zone() expects parameter 2 to be IntlTimeZone, integer given +error: 2, intlcal_set_time_zone(): intlcal_set_time_zone: bad arguments +bool(false) +error: 4096, Argument 1 passed to intlcal_set_time_zone() must be an instance of IntlCalendar, integer given +error: 2, intlcal_set_time_zone() expects parameter 1 to be IntlCalendar, integer given +error: 2, intlcal_set_time_zone(): intlcal_set_time_zone: bad arguments +bool(false) diff --git a/ext/intl/tests/calendar_setTimeZone_variation1.phpt b/ext/intl/tests/calendar_setTimeZone_variation1.phpt new file mode 100644 index 0000000000..b1cbb74edf --- /dev/null +++ b/ext/intl/tests/calendar_setTimeZone_variation1.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlCalendar::setTimeZone() variation with NULL arg +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('Europe/Amsterdam'); +print_r($intlcal->getTimeZone()->getID()); +echo "\n"; +var_dump($intlcal->get(IntlCalendar::FIELD_ZONE_OFFSET)); + +/* passing NULL has no effect */ +$intlcal->setTimeZone(null); +print_r($intlcal->getTimeZone()->getID()); +echo "\n"; +var_dump($intlcal->get(IntlCalendar::FIELD_ZONE_OFFSET)); + +?> +==DONE== +--EXPECT-- +Europe/Amsterdam +int(3600000) +Europe/Amsterdam +int(3600000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_setTime_basic.phpt b/ext/intl/tests/calendar_setTime_basic.phpt new file mode 100644 index 0000000000..802e41718a --- /dev/null +++ b/ext/intl/tests/calendar_setTime_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +IntlCalendar::setTime() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$time = strtotime('2012-02-29 00:00:00 +0000'); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->setTime($time * 1000); + +var_dump( + (float)$time*1000, + $intlcal->getTime()); + +$intlcal = IntlCalendar::createInstance('UTC'); +intlcal_set_time($intlcal,$time * 1000); +var_dump(intlcal_get_time($intlcal)); + +?> +==DONE== +--EXPECT-- +float(1330473600000) +float(1330473600000) +float(1330473600000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_setTime_error.phpt b/ext/intl/tests/calendar_setTime_error.phpt new file mode 100644 index 0000000000..e757bb3e64 --- /dev/null +++ b/ext/intl/tests/calendar_setTime_error.phpt @@ -0,0 +1,35 @@ +--TEST-- +IntlCalendar::setTime(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->setTime(1, 2)); +var_dump($c->setTime("jjj")); + +var_dump(intlcal_set_time($c, 1, 2)); +var_dump(intlcal_set_time(1)); +--EXPECTF-- + +Warning: IntlCalendar::setTime() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::setTime(): intlcal_set_time: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setTime() expects parameter 1 to be double, string given in %s on line %d + +Warning: IntlCalendar::setTime(): intlcal_set_time: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_set_time() expects exactly 2 parameters, 3 given in %s on line %d + +Warning: intlcal_set_time(): intlcal_set_time: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_set_time() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_set_basic.phpt b/ext/intl/tests/calendar_set_basic.phpt new file mode 100644 index 0000000000..2606ee92ba --- /dev/null +++ b/ext/intl/tests/calendar_set_basic.phpt @@ -0,0 +1,25 @@ +--TEST-- +IntlCalendar::set() basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance(); +var_dump($intlcal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 2)); +var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH)); +var_dump(intlcal_set($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH, 3)); +var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH)); + +?> +==DONE== +--EXPECT-- +bool(true) +int(2) +bool(true) +int(3) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/calendar_set_error.phpt b/ext/intl/tests/calendar_set_error.phpt new file mode 100644 index 0000000000..92c406f75c --- /dev/null +++ b/ext/intl/tests/calendar_set_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +IntlCalendar::set(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->set(1)); +var_dump($c->set(1, 2, 3, 4)); +var_dump($c->set(1, 2, 3, 4, 5, 6, 7)); +var_dump($c->set(-1, 2)); + +var_dump(intlcal_set($c, -1, 2)); +var_dump(intlcal_set(1, 2, 3)); +--EXPECTF-- + +Warning: IntlCalendar::set() expects at least 2 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::set(): intlcal_set: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::set(): intlcal_set: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::set(): intlcal_set: too many arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::set(): intlcal_set: invalid field in %s on line %d +bool(false) + +Warning: intlcal_set(): intlcal_set: invalid field in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_set() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_set_variation1.phpt b/ext/intl/tests/calendar_set_variation1.phpt new file mode 100644 index 0000000000..ba68eb1053 --- /dev/null +++ b/ext/intl/tests/calendar_set_variation1.phpt @@ -0,0 +1,39 @@ +--TEST-- +IntlCalendar::set() argument variations +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +$intlcal = IntlCalendar::createInstance('UTC'); +$intlcal->clear(); +var_dump($intlcal->set(2012, 1, 29)); +var_dump($intlcal->getTime(), + strtotime('2012-02-29 00:00:00 +0000') * 1000.); + +//two minutes to midnight! +var_dump($intlcal->set(2012, 1, 29, 23, 58)); +var_dump($intlcal->getTime(), + strtotime('2012-02-29 23:58:00 +0000') * 1000.); + +var_dump($intlcal->set(2012, 1, 29, 23, 58, 31)); +var_dump($intlcal->getTime(), + strtotime('2012-02-29 23:58:31 +0000') * 1000.); + +?> +==DONE== +--EXPECT-- +bool(true) +float(1330473600000) +float(1330473600000) +bool(true) +float(1330559880000) +float(1330559880000) +bool(true) +float(1330559911000) +float(1330559911000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/gregoriancalendar___construct_basic.phpt b/ext/intl/tests/gregoriancalendar___construct_basic.phpt new file mode 100644 index 0000000000..ed6b04341b --- /dev/null +++ b/ext/intl/tests/gregoriancalendar___construct_basic.phpt @@ -0,0 +1,49 @@ +--TEST-- +IntlGregorianCalendar::__construct(): basic +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +date_default_timezone_set('Europe/Amsterdam'); + +$intlcal = intlgregcal_create_instance(); +var_dump($intlcal->getTimeZone()->getId()); +var_dump($intlcal->getLocale(1)); + +$intlcal = new IntlGregorianCalendar('Europe/Lisbon', NULL); +var_dump($intlcal->getTimeZone()->getId()); +var_dump($intlcal->getLocale(1)); + +$intlcal = new IntlGregorianCalendar(NULL, 'pt_PT'); +var_dump($intlcal->getTimeZone()->getId()); +var_dump($intlcal->getLocale(1)); + +$intlcal = new IntlGregorianCalendar('Europe/Lisbon', 'pt_PT'); +var_dump($intlcal->getTimeZone()->getId()); +var_dump($intlcal->getLocale(1)); + +$intlcal = new IntlGregorianCalendar('Europe/Paris', 'fr_CA', NULL, NULL, NULL, NULL); +var_dump($intlcal->getTimeZone()->getId()); +var_dump($intlcal->getLocale(1)); + +var_dump($intlcal->getType()); +?> +==DONE== +--EXPECT-- +string(16) "Europe/Amsterdam" +string(5) "nl_NL" +string(13) "Europe/Lisbon" +string(5) "nl_NL" +string(16) "Europe/Amsterdam" +string(5) "pt_PT" +string(13) "Europe/Lisbon" +string(5) "pt_PT" +string(12) "Europe/Paris" +string(5) "fr_CA" +string(9) "gregorian" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/gregoriancalendar___construct_error.phpt b/ext/intl/tests/gregoriancalendar___construct_error.phpt new file mode 100644 index 0000000000..0e85394a48 --- /dev/null +++ b/ext/intl/tests/gregoriancalendar___construct_error.phpt @@ -0,0 +1,35 @@ +--TEST-- +IntlGregorianCalendar::__construct(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7)); +var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7,8)); +var_dump(intlgregcal_create_instance(1,2,3,4)); +var_dump(new IntlGregorianCalendar(1,2,NULL,4)); +var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array())); + + +--EXPECTF-- + +Warning: intlgregcal_create_instance(): intlgregcal_create_instance: too many arguments in %s on line %d +NULL + +Warning: intlgregcal_create_instance(): intlgregcal_create_instance: too many arguments in %s on line %d +NULL + +Warning: intlgregcal_create_instance(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d +NULL + +Warning: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d +NULL + +Warning: IntlGregorianCalendar::__construct() expects parameter 6 to be long, array given in %s on line %d + +Warning: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: bad arguments in %s on line %d +NULL diff --git a/ext/intl/tests/gregoriancalendar___construct_variant1.phpt b/ext/intl/tests/gregoriancalendar___construct_variant1.phpt new file mode 100644 index 0000000000..63266b792e --- /dev/null +++ b/ext/intl/tests/gregoriancalendar___construct_variant1.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlGregorianCalendar::__construct(): argument variants +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +date_default_timezone_set('Europe/Amsterdam'); + +$intlcal = intlgregcal_create_instance(2012, 1, 29, 16, 0, NULL); +var_dump($intlcal->getTimeZone()->getId()); +var_dump($intlcal->getTime(), (float)strtotime('2012-02-29 16:00:00') * 1000); + +$intlcal = new IntlGregorianCalendar(2012, 1, 29, 16, 7, 8); +var_dump($intlcal->getTime(), (float)strtotime('2012-02-29 16:07:08') * 1000); + +var_dump($intlcal->getType()); +?> +==DONE== +--EXPECT-- +string(16) "Europe/Amsterdam" +float(1330527600000) +float(1330527600000) +float(1330528028000) +float(1330528028000) +string(9) "gregorian" +==DONE== diff --git a/ext/intl/tests/gregoriancalendar_getGregorianChange_error.phpt b/ext/intl/tests/gregoriancalendar_getGregorianChange_error.phpt new file mode 100644 index 0000000000..7c0df58953 --- /dev/null +++ b/ext/intl/tests/gregoriancalendar_getGregorianChange_error.phpt @@ -0,0 +1,28 @@ +--TEST-- +IntlGregorianCalendar::getGregorianChange(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); +var_dump($c->getGregorianChange(1)); + +var_dump(intlgregcal_get_gregorian_change($c, 1)); +var_dump(intlgregcal_get_gregorian_change(1)); +--EXPECTF-- + +Warning: IntlGregorianCalendar::getGregorianChange() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlGregorianCalendar::getGregorianChange(): intlgregcal_get_gregorian_change: bad arguments in %s on line %d +bool(false) + +Warning: intlgregcal_get_gregorian_change() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlgregcal_get_gregorian_change(): intlgregcal_get_gregorian_change: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlgregcal_get_gregorian_change() must be an instance of IntlGregorianCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/gregoriancalendar_get_setGregorianChange_basic.phpt b/ext/intl/tests/gregoriancalendar_get_setGregorianChange_basic.phpt new file mode 100644 index 0000000000..b08ad7981f --- /dev/null +++ b/ext/intl/tests/gregoriancalendar_get_setGregorianChange_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +IntlGregorianCalendar::get/setGregorianChange(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +date_default_timezone_set('Europe/Amsterdam'); + +$intlcal = new IntlGregorianCalendar(); + +var_dump($intlcal->getGregorianChange()); + +var_dump($intlcal->setGregorianChange(0)); +var_dump(intlgregcal_get_gregorian_change($intlcal)); + +var_dump(intlgregcal_set_gregorian_change($intlcal, 1)); +var_dump($intlcal->getGregorianChange()); + +?> +==DONE== +--EXPECT-- +float(-12219292800000) +bool(true) +float(0) +bool(true) +float(1) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/gregoriancalendar_isLeapYear_basic.phpt b/ext/intl/tests/gregoriancalendar_isLeapYear_basic.phpt new file mode 100644 index 0000000000..b37452fcba --- /dev/null +++ b/ext/intl/tests/gregoriancalendar_isLeapYear_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +IntlGregorianCalendar::isLeapYear(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +date_default_timezone_set('Europe/Amsterdam'); + +$intlcal = new IntlGregorianCalendar(); + +var_dump($intlcal->isLeapYear(2012)); +var_dump($intlcal->isLeapYear(1900)); + +var_dump(intlgregcal_is_leap_year($intlcal, 2012)); +var_dump(intlgregcal_is_leap_year($intlcal, 1900)); +?> +==DONE== +--EXPECT-- +bool(true) +bool(false) +bool(true) +bool(false) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/gregoriancalendar_isLeapYear_error.phpt b/ext/intl/tests/gregoriancalendar_isLeapYear_error.phpt new file mode 100644 index 0000000000..06d05f47d6 --- /dev/null +++ b/ext/intl/tests/gregoriancalendar_isLeapYear_error.phpt @@ -0,0 +1,46 @@ +--TEST-- +IntlGregorianCalendar::isLeapYear(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); +var_dump($c->isLeapYear(2000, 2011)); +var_dump($c->isLeapYear()); +var_dump($c->isLeapYear("fgdf")); + +var_dump(intlgregcal_is_leap_year($c, 1, 2)); +var_dump(intlgregcal_is_leap_year($c)); +var_dump(intlgregcal_is_leap_year(1, 2)); +--EXPECTF-- + +Warning: IntlGregorianCalendar::isLeapYear() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlGregorianCalendar::isLeapYear(): intlgregcal_is_leap_year: bad arguments in %s on line %d +bool(false) + +Warning: IntlGregorianCalendar::isLeapYear() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlGregorianCalendar::isLeapYear(): intlgregcal_is_leap_year: bad arguments in %s on line %d +bool(false) + +Warning: IntlGregorianCalendar::isLeapYear() expects parameter 1 to be long, string given in %s on line %d + +Warning: IntlGregorianCalendar::isLeapYear(): intlgregcal_is_leap_year: bad arguments in %s on line %d +bool(false) + +Warning: intlgregcal_is_leap_year() expects exactly 2 parameters, 3 given in %s on line %d + +Warning: intlgregcal_is_leap_year(): intlgregcal_is_leap_year: bad arguments in %s on line %d +bool(false) + +Warning: intlgregcal_is_leap_year() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: intlgregcal_is_leap_year(): intlgregcal_is_leap_year: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlgregcal_is_leap_year() must be an instance of IntlGregorianCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/gregoriancalendar_setGregorianChange_error.phpt b/ext/intl/tests/gregoriancalendar_setGregorianChange_error.phpt new file mode 100644 index 0000000000..1d684c79d4 --- /dev/null +++ b/ext/intl/tests/gregoriancalendar_setGregorianChange_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlGregorianCalendar::setGregorianChange(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(); +var_dump($c->setGregorianChange()); +var_dump($c->setGregorianChange(1, 2)); +var_dump($c->setGregorianChange("sdfds")); + +var_dump(intlgregcal_set_gregorian_change($c)); +var_dump(intlgregcal_set_gregorian_change(1, 4.)); +--EXPECTF-- + +Warning: IntlGregorianCalendar::setGregorianChange() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlGregorianCalendar::setGregorianChange(): intlgregcal_set_gregorian_change: bad arguments in %s on line %d +bool(false) + +Warning: IntlGregorianCalendar::setGregorianChange() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlGregorianCalendar::setGregorianChange(): intlgregcal_set_gregorian_change: bad arguments in %s on line %d +bool(false) + +Warning: IntlGregorianCalendar::setGregorianChange() expects parameter 1 to be double, string given in %s on line %d + +Warning: IntlGregorianCalendar::setGregorianChange(): intlgregcal_set_gregorian_change: bad arguments in %s on line %d +bool(false) + +Warning: intlgregcal_set_gregorian_change() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: intlgregcal_set_gregorian_change(): intlgregcal_set_gregorian_change: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlgregcal_set_gregorian_change() must be an instance of IntlGregorianCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/timezone_clone_basic.phpt b/ext/intl/tests/timezone_clone_basic.phpt new file mode 100644 index 0000000000..a8ef83f864 --- /dev/null +++ b/ext/intl/tests/timezone_clone_basic.phpt @@ -0,0 +1,51 @@ +--TEST-- +IntlTimeZone clone handler: basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz1 = IntlTimeZone::createTimeZone('Europe/Amsterdam'); +print_r($tz1); +print_r(clone $tz1); + +//clone non-owned object +$gmt = IntlTimeZone::getGMT(); +print_r($gmt); +print_r(clone $gmt); + +?> +==DONE== +--EXPECTF-- +IntlTimeZone Object +( + [valid] => 1 + [id] => Europe/Amsterdam + [rawOffset] => 3600000 + [currentOffset] => %d +) +IntlTimeZone Object +( + [valid] => 1 + [id] => Europe/Amsterdam + [rawOffset] => 3600000 + [currentOffset] => %d +) +IntlTimeZone Object +( + [valid] => 1 + [id] => GMT + [rawOffset] => 0 + [currentOffset] => 0 +) +IntlTimeZone Object +( + [valid] => 1 + [id] => GMT + [rawOffset] => 0 + [currentOffset] => 0 +) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_clone_error.phpt b/ext/intl/tests/timezone_clone_error.phpt new file mode 100644 index 0000000000..df501be3b4 --- /dev/null +++ b/ext/intl/tests/timezone_clone_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +IntlTimeZone clone handler: error test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +class A extends IntlTimeZone { +function __construct() {} +} + +$tz = new A(); +var_dump($tz); +try { +var_dump(clone $tz); +} catch (Exception $e) { + var_dump(get_class($e), $e->getMessage()); +} + +?> +==DONE== +--EXPECT-- +object(A)#1 (1) { + ["valid"]=> + bool(false) +} +string(9) "Exception" +string(39) "Cannot clone unconstructed IntlTimeZone" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_countEquivalentIDs_basic.phpt b/ext/intl/tests/timezone_countEquivalentIDs_basic.phpt new file mode 100644 index 0000000000..ec3e4050ab --- /dev/null +++ b/ext/intl/tests/timezone_countEquivalentIDs_basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +IntlTimeZone::countEquivalentIDs(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$count = IntlTimeZone::countEquivalentIDs('Europe/Lisbon'); +var_dump($count >= 2); + +$count2 = intltz_count_equivalent_ids('Europe/Lisbon'); +var_dump($count2 == $count); +?> +==DONE== +--EXPECT-- +bool(true) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_countEquivalentIDs_error.phpt b/ext/intl/tests/timezone_countEquivalentIDs_error.phpt new file mode 100644 index 0000000000..4d8f4bc3e3 --- /dev/null +++ b/ext/intl/tests/timezone_countEquivalentIDs_error.phpt @@ -0,0 +1,35 @@ +--TEST-- +IntlTimeZone::countEquivalentIDs(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::countEquivalentIDs()); +var_dump(IntlTimeZone::countEquivalentIDs(array())); +var_dump(IntlTimeZone::countEquivalentIDs("foo\x80")); +var_dump(IntlTimeZone::countEquivalentIDs("foo bar", 7)); + + +--EXPECTF-- + +Warning: IntlTimeZone::countEquivalentIDs() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlTimeZone::countEquivalentIDs(): intltz_count_equivalent_ids: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::countEquivalentIDs() expects parameter 1 to be string, array given in %s on line %d + +Warning: IntlTimeZone::countEquivalentIDs(): intltz_count_equivalent_ids: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::countEquivalentIDs(): intltz_count_equivalent_ids: could not convert time zone id to UTF-16 in %s on line %d +bool(false) + +Warning: IntlTimeZone::countEquivalentIDs() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlTimeZone::countEquivalentIDs(): intltz_count_equivalent_ids: bad arguments in %s on line %d +bool(false) diff --git a/ext/intl/tests/timezone_createDefault_basic.phpt b/ext/intl/tests/timezone_createDefault_basic.phpt new file mode 100644 index 0000000000..a18899fc4f --- /dev/null +++ b/ext/intl/tests/timezone_createDefault_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +IntlTimeZone::createDefault(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$tz = IntlTimeZone::createDefault(); +print_r($tz); +$tz = intltz_create_default(); +print_r($tz); +?> +==DONE== +--EXPECTF-- +IntlTimeZone Object +( + [valid] => 1 + [id] => %s + [rawOffset] => %d + [currentOffset] => %d +) +IntlTimeZone Object +( + [valid] => 1 + [id] => %s + [rawOffset] => %d + [currentOffset] => %d +) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_createDefault_error.phpt b/ext/intl/tests/timezone_createDefault_error.phpt new file mode 100644 index 0000000000..0724898219 --- /dev/null +++ b/ext/intl/tests/timezone_createDefault_error.phpt @@ -0,0 +1,19 @@ +--TEST-- +IntlTimeZone::createDefault(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::createDefault(4)); + + +--EXPECTF-- + +Warning: IntlTimeZone::createDefault() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::createDefault(): intltz_create_default: bad arguments in %s on line %d +NULL diff --git a/ext/intl/tests/timezone_createEnumeration_basic.phpt b/ext/intl/tests/timezone_createEnumeration_basic.phpt new file mode 100644 index 0000000000..2df32562b1 --- /dev/null +++ b/ext/intl/tests/timezone_createEnumeration_basic.phpt @@ -0,0 +1,26 @@ +--TEST-- +IntlTimeZone::createEnumeration(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$tz = IntlTimeZone::createEnumeration(); +var_dump(get_class($tz)); +$count = count(iterator_to_array($tz)); +var_dump($count > 300); + +$tz = intltz_create_enumeration(); +var_dump(get_class($tz)); +$count2 = count(iterator_to_array($tz)); +var_dump($count == $count2); +?> +==DONE== +--EXPECT-- +string(12) "IntlIterator" +bool(true) +string(12) "IntlIterator" +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_createEnumeration_error.phpt b/ext/intl/tests/timezone_createEnumeration_error.phpt new file mode 100644 index 0000000000..e1e7cb9333 --- /dev/null +++ b/ext/intl/tests/timezone_createEnumeration_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +IntlTimeZone::createEnumeration(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::createEnumeration(array())); +var_dump(IntlTimeZone::createEnumeration(1, 2)); + + +--EXPECTF-- + +Warning: IntlTimeZone::createEnumeration(): intltz_create_enumeration: invalid argument type in %s on line %d +bool(false) + +Warning: IntlTimeZone::createEnumeration() expects at most 1 parameter, 2 given in %s on line %d + +Warning: IntlTimeZone::createEnumeration(): intltz_create_enumeration: bad arguments in %s on line %d +bool(false) diff --git a/ext/intl/tests/timezone_createEnumeration_variation1.phpt b/ext/intl/tests/timezone_createEnumeration_variation1.phpt new file mode 100644 index 0000000000..30fc43660e --- /dev/null +++ b/ext/intl/tests/timezone_createEnumeration_variation1.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlTimeZone::createEnumeration(): variant with offset +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$tz = IntlTimeZone::createEnumeration(3600000); +var_dump(get_class($tz)); +$count = count(iterator_to_array($tz)); +var_dump($count > 20); + +$tz->rewind(); +var_dump(in_array('Europe/Amsterdam', iterator_to_array($tz))); + +?> +==DONE== +--EXPECT-- +string(12) "IntlIterator" +bool(true) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_createEnumeration_variation2.phpt b/ext/intl/tests/timezone_createEnumeration_variation2.phpt new file mode 100644 index 0000000000..ddf1a6ece1 --- /dev/null +++ b/ext/intl/tests/timezone_createEnumeration_variation2.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlTimeZone::createEnumeration(): variant with country +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$tz = IntlTimeZone::createEnumeration('NL'); +var_dump(get_class($tz)); +$count = count(iterator_to_array($tz)); +var_dump($count >= 1); + +$tz->rewind(); +var_dump(in_array('Europe/Amsterdam', iterator_to_array($tz))); + +?> +==DONE== +--EXPECT-- +string(12) "IntlIterator" +bool(true) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_createTimeZoneIDEnumeration_basic.phpt b/ext/intl/tests/timezone_createTimeZoneIDEnumeration_basic.phpt new file mode 100644 index 0000000000..c908513926 --- /dev/null +++ b/ext/intl/tests/timezone_createTimeZoneIDEnumeration_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +IntlTimeZone::createTimeZoneIDEnumeration(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$enum = IntlTimeZone::createTimeZoneIDEnumeration( + IntlTimeZone::TYPE_ANY, + 'PT', + -3600000); +print_r(iterator_to_array($enum)); + +$enum = intltz_create_time_zone_id_enumeration( + IntlTimeZone::TYPE_ANY, + 'PT', + -3600000); +print_r(iterator_to_array($enum)); +?> +==DONE== +--EXPECT-- +Array +( + [0] => Atlantic/Azores +) +Array +( + [0] => Atlantic/Azores +) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_createTimeZoneIDEnumeration_error.phpt b/ext/intl/tests/timezone_createTimeZoneIDEnumeration_error.phpt new file mode 100644 index 0000000000..5c7dbe5af3 --- /dev/null +++ b/ext/intl/tests/timezone_createTimeZoneIDEnumeration_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlTimeZone::createTimeZoneIDEnumeration(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::createTimeZoneIDEnumeration()); +var_dump(IntlTimeZone::createTimeZoneIDEnumeration(array())); +var_dump(IntlTimeZone::createTimeZoneIDEnumeration(-1)); +var_dump(IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY, array())); +var_dump(IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY, "PT", "a80")); + +--EXPECTF-- + +Warning: IntlTimeZone::createTimeZoneIDEnumeration() expects at least 1 parameter, 0 given in %s on line %d + +Warning: IntlTimeZone::createTimeZoneIDEnumeration(): intltz_create_time_zone_id_enumeration: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::createTimeZoneIDEnumeration() expects parameter 1 to be long, array given in %s on line %d + +Warning: IntlTimeZone::createTimeZoneIDEnumeration(): intltz_create_time_zone_id_enumeration: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::createTimeZoneIDEnumeration(): intltz_create_time_zone_id_enumeration: bad zone type in %s on line %d +bool(false) + +Warning: IntlTimeZone::createTimeZoneIDEnumeration() expects parameter 2 to be string, array given in %s on line %d + +Warning: IntlTimeZone::createTimeZoneIDEnumeration(): intltz_create_time_zone_id_enumeration: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::createTimeZoneIDEnumeration() expects parameter 3 to be long, string given in %s on line %d + +Warning: IntlTimeZone::createTimeZoneIDEnumeration(): intltz_create_time_zone_id_enumeration: bad arguments in %s on line %d +bool(false) diff --git a/ext/intl/tests/timezone_createTimeZoneIDEnumeration_variant1.phpt b/ext/intl/tests/timezone_createTimeZoneIDEnumeration_variant1.phpt new file mode 100644 index 0000000000..1447458a7f --- /dev/null +++ b/ext/intl/tests/timezone_createTimeZoneIDEnumeration_variant1.phpt @@ -0,0 +1,30 @@ +--TEST-- +IntlTimeZone::createTimeZoneIDEnumeration(): variant without offset +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$enum = IntlTimeZone::createTimeZoneIDEnumeration( + IntlTimeZone::TYPE_ANY, + 'PT'); +$values = iterator_to_array($enum); +var_dump(in_array('Europe/Lisbon', $values)); +var_dump(in_array('Atlantic/Azores', $values)); + +$enum = IntlTimeZone::createTimeZoneIDEnumeration( + IntlTimeZone::TYPE_ANY, + 'PT', + null); +$values2 = iterator_to_array($enum); +var_dump($values2 == $values); + +?> +==DONE== +--EXPECT-- +bool(true) +bool(true) +bool(true) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_createTimeZoneIDEnumeration_variant2.phpt b/ext/intl/tests/timezone_createTimeZoneIDEnumeration_variant2.phpt new file mode 100644 index 0000000000..7e1207d344 --- /dev/null +++ b/ext/intl/tests/timezone_createTimeZoneIDEnumeration_variant2.phpt @@ -0,0 +1,50 @@ +--TEST-- +IntlTimeZone::createTimeZoneIDEnumeration(): variant without region +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$enum = IntlTimeZone::createTimeZoneIDEnumeration( + IntlTimeZone::TYPE_ANY); +$countAny = count(iterator_to_array($enum)); +$enum = IntlTimeZone::createTimeZoneIDEnumeration( + IntlTimeZone::TYPE_CANONICAL); +$countCanonical = count(iterator_to_array($enum)); +$enum = IntlTimeZone::createTimeZoneIDEnumeration( + IntlTimeZone::TYPE_CANONICAL_LOCATION); +$countCanonicalLocation = count(iterator_to_array($enum)); + +var_dump($countAny > $countCanonical); +var_dump($countCanonical > $countCanonicalLocation); + +$enum = IntlTimeZone::createTimeZoneIDEnumeration( + IntlTimeZone::TYPE_ANY, null, null); +$countAny2 = count(iterator_to_array($enum)); +var_dump($countAny == $countAny2); + +$enum = IntlTimeZone::createTimeZoneIDEnumeration( + IntlTimeZone::TYPE_ANY, null, -3600000); +$values = iterator_to_array($enum); + +print_r( +array_values( +array_intersect($values, +array('Etc/GMT+1', 'Atlantic/Azores')) +)); + + +?> +==DONE== +--EXPECT-- +bool(true) +bool(true) +bool(true) +Array +( + [0] => Atlantic/Azores + [1] => Etc/GMT+1 +) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_createTimeZone_basic.phpt b/ext/intl/tests/timezone_createTimeZone_basic.phpt new file mode 100644 index 0000000000..bb5e51e10b --- /dev/null +++ b/ext/intl/tests/timezone_createTimeZone_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +IntlTimeZone::createTimeZone(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$tz = IntlTimeZone::createTimeZone('GMT+01:00'); +print_r($tz); +$tz = intltz_create_time_zone('GMT+01:00'); +print_r($tz); +?> +==DONE== +--EXPECT-- +IntlTimeZone Object +( + [valid] => 1 + [id] => GMT+01:00 + [rawOffset] => 3600000 + [currentOffset] => 3600000 +) +IntlTimeZone Object +( + [valid] => 1 + [id] => GMT+01:00 + [rawOffset] => 3600000 + [currentOffset] => 3600000 +) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_createTimeZone_error.phpt b/ext/intl/tests/timezone_createTimeZone_error.phpt new file mode 100644 index 0000000000..2be821a67e --- /dev/null +++ b/ext/intl/tests/timezone_createTimeZone_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +IntlTimeZone::createTimeZone(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::createTimeZone()); +var_dump(IntlTimeZone::createTimeZone(new stdClass)); +var_dump(IntlTimeZone::createTimeZone("foo bar", 4)); +var_dump(IntlTimeZone::createTimeZone("foo\x80")); + +--EXPECTF-- + +Warning: IntlTimeZone::createTimeZone() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlTimeZone::createTimeZone(): intltz_create_time_zone: bad arguments in %s on line %d +NULL + +Warning: IntlTimeZone::createTimeZone() expects parameter 1 to be string, object given in %s on line %d + +Warning: IntlTimeZone::createTimeZone(): intltz_create_time_zone: bad arguments in %s on line %d +NULL + +Warning: IntlTimeZone::createTimeZone() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlTimeZone::createTimeZone(): intltz_create_time_zone: bad arguments in %s on line %d +NULL + +Warning: IntlTimeZone::createTimeZone(): intltz_create_time_zone: could not convert time zone id to UTF-16 in %s on line %d +NULL diff --git a/ext/intl/tests/timezone_equals_basic.phpt b/ext/intl/tests/timezone_equals_basic.phpt new file mode 100644 index 0000000000..105ae8582f --- /dev/null +++ b/ext/intl/tests/timezone_equals_basic.phpt @@ -0,0 +1,33 @@ +--TEST-- +IntlTimeZone equals handler: basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz1 = intltz_create_time_zone('Europe/Lisbon'); +$tz2 = intltz_create_time_zone('Europe/Lisbon'); +echo "Comparison to self:\n"; +var_dump($tz1 == $tz1); +echo "Comparison to equal instance:\n"; +var_dump($tz1 == $tz2); +echo "Comparison to equivalent instance:\n"; +var_dump($tz1 == intltz_create_time_zone('Portugal')); +echo "Comparison to GMT:\n"; +var_dump($tz1 == intltz_get_gmt()); + +?> +==DONE== +--EXPECT-- +Comparison to self: +bool(true) +Comparison to equal instance: +bool(true) +Comparison to equivalent instance: +bool(false) +Comparison to GMT: +bool(false) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_equals_error.phpt b/ext/intl/tests/timezone_equals_error.phpt new file mode 100644 index 0000000000..d8d027a761 --- /dev/null +++ b/ext/intl/tests/timezone_equals_error.phpt @@ -0,0 +1,43 @@ +--TEST-- +IntlTimeZone equals handler: error test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +class A extends IntlTimeZone { +function __construct() {} +} + +$tz = new A(); +$tz2 = intltz_get_gmt(); +var_dump($tz, $tz2); +try { +var_dump($tz == $tz2); +} catch (Exception $e) { + var_dump(get_class($e), $e->getMessage()); +} + +?> +==DONE== +--EXPECT-- +object(A)#1 (1) { + ["valid"]=> + bool(false) +} +object(IntlTimeZone)#2 (4) { + ["valid"]=> + bool(true) + ["id"]=> + string(3) "GMT" + ["rawOffset"]=> + int(0) + ["currentOffset"]=> + int(0) +} +string(9) "Exception" +string(63) "Comparison with at least one unconstructed IntlTimeZone operand" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getCanonicalID_basic.phpt b/ext/intl/tests/timezone_getCanonicalID_basic.phpt new file mode 100644 index 0000000000..897e9a9edc --- /dev/null +++ b/ext/intl/tests/timezone_getCanonicalID_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +IntlTimeZone::getCanonicalID: basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +print_R(IntlTimeZone::getCanonicalID('Portugal')); +echo "\n"; +print_R(intltz_get_canonical_id('Portugal')); +echo "\n"; +?> +==DONE== +--EXPECT-- +Europe/Lisbon +Europe/Lisbon +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getCanonicalID_error.phpt b/ext/intl/tests/timezone_getCanonicalID_error.phpt new file mode 100644 index 0000000000..c7ffb45b77 --- /dev/null +++ b/ext/intl/tests/timezone_getCanonicalID_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +IntlTimeZone::getCanonicalID(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::getCanonicalID()); +var_dump(IntlTimeZone::getCanonicalID(array())); +var_dump(IntlTimeZone::getCanonicalID("foo\x81")); +var_dump(IntlTimeZone::getCanonicalID('foobar', null)); + + +--EXPECTF-- + +Warning: IntlTimeZone::getCanonicalID() expects at least 1 parameter, 0 given in %s on line %d + +Warning: IntlTimeZone::getCanonicalID(): intltz_get_canonical_id: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getCanonicalID() expects parameter 1 to be string, array given in %s on line %d + +Warning: IntlTimeZone::getCanonicalID(): intltz_get_canonical_id: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getCanonicalID(): intltz_get_canonical_id: could not convert time zone id to UTF-16 in %s on line %d +bool(false) + +Fatal error: Cannot pass parameter 2 by reference in %s on line %d diff --git a/ext/intl/tests/timezone_getCanonicalID_variant1.phpt b/ext/intl/tests/timezone_getCanonicalID_variant1.phpt new file mode 100644 index 0000000000..92a7f07378 --- /dev/null +++ b/ext/intl/tests/timezone_getCanonicalID_variant1.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlTimeZone::getCanonicalID(): second argument +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::getCanonicalID('Portugal', $isSystemId)); +var_dump($isSystemId); + +var_dump(IntlTimeZone::getCanonicalID('GMT +01:25', $isSystemId)); +var_dump($isSystemId); + +?> +==DONE== +--EXPECT-- +string(13) "Europe/Lisbon" +bool(true) +string(0) "" +bool(false) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getDSTSavings_basic.phpt b/ext/intl/tests/timezone_getDSTSavings_basic.phpt new file mode 100644 index 0000000000..8dee5b8e94 --- /dev/null +++ b/ext/intl/tests/timezone_getDSTSavings_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +IntlTimeZone::getDSTSavings(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($lsb->getDSTSavings()); + +var_dump(intltz_get_dst_savings($lsb)); + +?> +==DONE== +--EXPECT-- +int(3600000) +int(3600000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getDSTSavings_error.phpt b/ext/intl/tests/timezone_getDSTSavings_error.phpt new file mode 100644 index 0000000000..e1469f4ac6 --- /dev/null +++ b/ext/intl/tests/timezone_getDSTSavings_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +IntlTimeZone::getDSTSavings(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($tz->getDSTSavings(array())); + +var_dump(intltz_get_dst_savings(null)); + +--EXPECTF-- + +Warning: IntlTimeZone::getDSTSavings() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::getDSTSavings(): intltz_get_dst_savings: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intltz_get_dst_savings() must be an instance of IntlTimeZone, null given in %s on line %d diff --git a/ext/intl/tests/timezone_getDisplayName_basic.phpt b/ext/intl/tests/timezone_getDisplayName_basic.phpt new file mode 100644 index 0000000000..0c485ffc43 --- /dev/null +++ b/ext/intl/tests/timezone_getDisplayName_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +IntlTimeZone::getDisplayName(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); + +ini_set('intl.default_locale', 'en_US'); +var_dump($lsb->getDisplayName()); + +ini_set('intl.default_locale', 'pt_PT'); +var_dump($lsb->getDisplayName()); + +?> +==DONE== +--EXPECT-- +string(21) "Western European Time" +string(24) "Hora da Europa Ocidental" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getDisplayName_error.phpt b/ext/intl/tests/timezone_getDisplayName_error.phpt new file mode 100644 index 0000000000..a12f85c855 --- /dev/null +++ b/ext/intl/tests/timezone_getDisplayName_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +IntlTimeZone::getDisplayName(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($tz->getDisplayName(array())); +var_dump($tz->getDisplayName(false, array())); +var_dump($tz->getDisplayName(false, -1)); +var_dump($tz->getDisplayName(false, IntlTimeZone::DISPLAY_SHORT, array())); +var_dump($tz->getDisplayName(false, IntlTimeZone::DISPLAY_SHORT, NULL, NULL)); + +var_dump(intltz_get_display_name(null, IntlTimeZone::DISPLAY_SHORT, false, 'pt_PT')); + +--EXPECTF-- + +Warning: IntlTimeZone::getDisplayName() expects parameter 1 to be boolean, array given in %s on line %d + +Warning: IntlTimeZone::getDisplayName(): intltz_get_display_name: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getDisplayName() expects parameter 2 to be long, array given in %s on line %d + +Warning: IntlTimeZone::getDisplayName(): intltz_get_display_name: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getDisplayName(): intltz_get_display_name: wrong display type in %s on line %d +bool(false) + +Warning: IntlTimeZone::getDisplayName() expects parameter 3 to be string, array given in %s on line %d + +Warning: IntlTimeZone::getDisplayName(): intltz_get_display_name: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getDisplayName() expects at most 3 parameters, 4 given in %s on line %d + +Warning: IntlTimeZone::getDisplayName(): intltz_get_display_name: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intltz_get_display_name() must be an instance of IntlTimeZone, null given in %s on line %d diff --git a/ext/intl/tests/timezone_getDisplayName_variant1.phpt b/ext/intl/tests/timezone_getDisplayName_variant1.phpt new file mode 100644 index 0000000000..3f38344b0e --- /dev/null +++ b/ext/intl/tests/timezone_getDisplayName_variant1.phpt @@ -0,0 +1,26 @@ +--TEST-- +IntlTimeZone::getDisplayName(): daylight parameter effect +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("error_reporting", -1); +ini_set("display_errors", 1); + +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); + +ini_set('intl.default_locale', 'en_US'); +var_dump($lsb->getDisplayName()); +var_dump($lsb->getDisplayName(false)); +var_dump($lsb->getDisplayName(true)); + +?> +==DONE== +--EXPECT-- +string(21) "Western European Time" +string(21) "Western European Time" +string(28) "Western European Summer Time" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getDisplayName_variant2.phpt b/ext/intl/tests/timezone_getDisplayName_variant2.phpt new file mode 100644 index 0000000000..aa452dadad --- /dev/null +++ b/ext/intl/tests/timezone_getDisplayName_variant2.phpt @@ -0,0 +1,36 @@ +--TEST-- +IntlTimeZone::getDisplayName(): type parameter +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("error_reporting", -1); +ini_set("display_errors", 1); + +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); + +ini_set('intl.default_locale', 'en_US'); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_SHORT)); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_LONG)); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_SHORT_GENERIC)); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_LONG_GENERIC)); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_SHORT_GMT)); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_LONG_GMT)); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_SHORT_COMMONLY_USED)); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_GENERIC_LOCATION)); + +?> +==DONE== +--EXPECT-- +string(3) "WET" +string(21) "Western European Time" +string(22) "Portugal Time (Lisbon)" +string(22) "Portugal Time (Lisbon)" +string(5) "+0000" +string(3) "GMT" +string(3) "GMT" +string(22) "Portugal Time (Lisbon)" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getDisplayName_variant3.phpt b/ext/intl/tests/timezone_getDisplayName_variant3.phpt new file mode 100644 index 0000000000..41cab8d0b6 --- /dev/null +++ b/ext/intl/tests/timezone_getDisplayName_variant3.phpt @@ -0,0 +1,26 @@ +--TEST-- +IntlTimeZone::getDisplayName(): locale parameter +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("error_reporting", -1); +ini_set("display_errors", 1); + +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); + +ini_set('intl.default_locale', 'en_US'); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_LONG)); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_LONG, NULL)); +var_dump($lsb->getDisplayName(false, IntlTimeZone::DISPLAY_LONG, 'pt_PT')); + +?> +==DONE== +--EXPECT-- +string(21) "Western European Time" +string(21) "Western European Time" +string(24) "Hora da Europa Ocidental" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getEquivalentID_basic.phpt b/ext/intl/tests/timezone_getEquivalentID_basic.phpt new file mode 100644 index 0000000000..8af1e20897 --- /dev/null +++ b/ext/intl/tests/timezone_getEquivalentID_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +IntlTimeZone::getEquivalentID(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +print_R(IntlTimeZone::getEquivalentID('Europe/Lisbon', "1")); +echo "\n"; +print_R(intltz_get_equivalent_id('Europe/Lisbon', 1)); +echo "\n"; +?> +==DONE== +--EXPECT-- +Portugal +Portugal +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getEquivalentID_error.phpt b/ext/intl/tests/timezone_getEquivalentID_error.phpt new file mode 100644 index 0000000000..b3f344b54d --- /dev/null +++ b/ext/intl/tests/timezone_getEquivalentID_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +IntlTimeZone::getEquivalentID(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::getEquivalentID('foo')); +var_dump(IntlTimeZone::getEquivalentID('foo', 'bar')); +var_dump(IntlTimeZone::getEquivalentID('Europe/Lisbon', 0, 1)); +var_dump(IntlTimeZone::getEquivalentID("foo\x80", 0)); + +--EXPECTF-- + +Warning: IntlTimeZone::getEquivalentID() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::getEquivalentID(): intltz_get_equivalent_id: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getEquivalentID() expects parameter 2 to be long, string given in %s on line %d + +Warning: IntlTimeZone::getEquivalentID(): intltz_get_equivalent_id: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getEquivalentID() expects exactly 2 parameters, 3 given in %s on line %d + +Warning: IntlTimeZone::getEquivalentID(): intltz_get_equivalent_id: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getEquivalentID(): intltz_get_equivalent_id: could not convert time zone id to UTF-16 in %s on line %d +bool(false) diff --git a/ext/intl/tests/timezone_getErrorCodeMessage_basic.phpt b/ext/intl/tests/timezone_getErrorCodeMessage_basic.phpt new file mode 100644 index 0000000000..d3a3dee47d --- /dev/null +++ b/ext/intl/tests/timezone_getErrorCodeMessage_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +IntlTimeZone::getErrorCode/Message(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); + +var_dump($lsb->getErrorCode()); +var_dump($lsb->getErrorMessage()); + +var_dump($lsb->getOffset(INF, 1, $a, $b)); + +var_dump($lsb->getErrorCode()); +var_dump($lsb->getErrorMessage()); + +?> +==DONE== +--EXPECTF-- +int(0) +string(12) "U_ZERO_ERROR" + +Warning: IntlTimeZone::getOffset(): intltz_get_offset: error obtaining offset in %s on line %d +bool(false) +int(1) +string(67) "intltz_get_offset: error obtaining offset: U_ILLEGAL_ARGUMENT_ERROR" +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getErrorCode_error.phpt b/ext/intl/tests/timezone_getErrorCode_error.phpt new file mode 100644 index 0000000000..b56d3b0a48 --- /dev/null +++ b/ext/intl/tests/timezone_getErrorCode_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +IntlTimeZone::getErrorCode(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($tz->getErrorCode(array())); + +var_dump(intltz_get_error_code(null)); + +--EXPECTF-- + +Warning: IntlTimeZone::getErrorCode() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::getErrorCode(): intltz_get_error_code: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intltz_get_error_code() must be an instance of IntlTimeZone, null given in %s on line %d diff --git a/ext/intl/tests/timezone_getErrorMessage_error.phpt b/ext/intl/tests/timezone_getErrorMessage_error.phpt new file mode 100644 index 0000000000..067dcdc13b --- /dev/null +++ b/ext/intl/tests/timezone_getErrorMessage_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +IntlTimeZone::getErrorMessage(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($tz->getErrorMessage(array())); + +var_dump(intltz_get_error_message(null)); + +--EXPECTF-- + +Warning: IntlTimeZone::getErrorMessage() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::getErrorMessage(): intltz_get_error_message: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intltz_get_error_message() must be an instance of IntlTimeZone, null given in %s on line %d diff --git a/ext/intl/tests/timezone_getGMT_basic.phpt b/ext/intl/tests/timezone_getGMT_basic.phpt new file mode 100644 index 0000000000..99b3fa22ca --- /dev/null +++ b/ext/intl/tests/timezone_getGMT_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +IntlTimeZone::getGMT(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$tz = IntlTimeZone::getGMT(); +print_r($tz); +$tz = intltz_get_gmt(); +print_r($tz); +?> +==DONE== +--EXPECT-- +IntlTimeZone Object +( + [valid] => 1 + [id] => GMT + [rawOffset] => 0 + [currentOffset] => 0 +) +IntlTimeZone Object +( + [valid] => 1 + [id] => GMT + [rawOffset] => 0 + [currentOffset] => 0 +) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getGMT_error.phpt b/ext/intl/tests/timezone_getGMT_error.phpt new file mode 100644 index 0000000000..15afb765e4 --- /dev/null +++ b/ext/intl/tests/timezone_getGMT_error.phpt @@ -0,0 +1,19 @@ +--TEST-- +IntlTimeZone::getGMT(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::getGMT(4)); + + +--EXPECTF-- + +Warning: IntlTimeZone::getGMT() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::getGMT(): intltz_get_gmt: bad arguments in %s on line %d +NULL diff --git a/ext/intl/tests/timezone_getID_error.phpt b/ext/intl/tests/timezone_getID_error.phpt new file mode 100644 index 0000000000..b239b3facf --- /dev/null +++ b/ext/intl/tests/timezone_getID_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +IntlTimeZone::getID(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($tz->getID('foo')); +intltz_get_id(null); + + +--EXPECTF-- + +Warning: IntlTimeZone::getID() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::getID(): intltz_get_id: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intltz_get_id() must be an instance of IntlTimeZone, null given in %s on line %d diff --git a/ext/intl/tests/timezone_getOffset_basic.phpt b/ext/intl/tests/timezone_getOffset_basic.phpt new file mode 100644 index 0000000000..7c89a3ef65 --- /dev/null +++ b/ext/intl/tests/timezone_getOffset_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +IntlTimeZone::getOffset(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$ams = IntlTimeZone::createTimeZone('Europe/Amsterdam'); + +$date = strtotime("1 July 2012 +0000"); + +var_dump($ams->getOffset($date *1000., true, $rawOffset, $dstOffset), + $rawOffset, $dstOffset); + +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); + +var_dump(intltz_get_offset($lsb, $date *1000., true, $rawOffset, $dstOffset), + $rawOffset, $dstOffset); + +?> +==DONE== +--EXPECT-- +bool(true) +int(3600000) +int(3600000) +bool(true) +int(0) +int(3600000) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getOffset_error.phpt b/ext/intl/tests/timezone_getOffset_error.phpt new file mode 100644 index 0000000000..73555002c0 --- /dev/null +++ b/ext/intl/tests/timezone_getOffset_error.phpt @@ -0,0 +1,33 @@ +--TEST-- +IntlTimeZone::getOffset(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($tz->getOffset(INF, true, $a, $a)); +var_dump($tz->getOffset(time()*1000, true, $a)); +var_dump($tz->getOffset(time()*1000, true, $a, $a, $a)); + +intltz_get_offset(null, time()*1000, false, $a, $a); + +--EXPECTF-- + +Warning: IntlTimeZone::getOffset(): intltz_get_offset: error obtaining offset in %s on line %d +bool(false) + +Warning: IntlTimeZone::getOffset() expects exactly 4 parameters, 3 given in %s on line %d + +Warning: IntlTimeZone::getOffset(): intltz_get_offset: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getOffset() expects exactly 4 parameters, 5 given in %s on line %d + +Warning: IntlTimeZone::getOffset(): intltz_get_offset: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intltz_get_offset() must be an instance of IntlTimeZone, null given in %s on line %d diff --git a/ext/intl/tests/timezone_getRawOffset_basic.phpt b/ext/intl/tests/timezone_getRawOffset_basic.phpt new file mode 100644 index 0000000000..a2b4debf2b --- /dev/null +++ b/ext/intl/tests/timezone_getRawOffset_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +IntlTimeZone::getRawOffset(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$ams = IntlTimeZone::createTimeZone('Europe/Amsterdam'); +var_dump($ams->getRawOffset()); + +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump(intltz_get_raw_offset($lsb)); + +?> +==DONE== +--EXPECT-- +int(3600000) +int(0) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getRawOffset_error.phpt b/ext/intl/tests/timezone_getRawOffset_error.phpt new file mode 100644 index 0000000000..eb6aac02cd --- /dev/null +++ b/ext/intl/tests/timezone_getRawOffset_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +IntlTimeZone::getRawOffset(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($tz->getRawOffset('foo')); + +intltz_get_raw_offset(null); + +--EXPECTF-- + +Warning: IntlTimeZone::getRawOffset() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::getRawOffset(): intltz_get_raw_offset: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intltz_get_raw_offset() must be an instance of IntlTimeZone, null given in %s on line %d diff --git a/ext/intl/tests/timezone_getRegion_basic.phpt b/ext/intl/tests/timezone_getRegion_basic.phpt new file mode 100644 index 0000000000..ba4285a971 --- /dev/null +++ b/ext/intl/tests/timezone_getRegion_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +IntlTimeZone::getRegion(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +print_R(IntlTimeZone::getRegion('Europe/Amsterdam')); +echo "\n"; +print_R(intltz_get_region('Europe/Amsterdam')); +echo "\n"; +?> +==DONE== +--EXPECT-- +NL +NL +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_getRegion_error.phpt b/ext/intl/tests/timezone_getRegion_error.phpt new file mode 100644 index 0000000000..9d08bbbde0 --- /dev/null +++ b/ext/intl/tests/timezone_getRegion_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +IntlTimeZone::getRegion(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::getRegion()); +var_dump(IntlTimeZone::getRegion(array())); +var_dump(IntlTimeZone::getRegion('Europe/Lisbon', 4)); +var_dump(IntlTimeZone::getRegion("foo\x81")); +var_dump(IntlTimeZone::getRegion("foo")); + + + +--EXPECTF-- + +Warning: IntlTimeZone::getRegion() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlTimeZone::getRegion(): intltz_get_region: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getRegion() expects parameter 1 to be string, array given in %s on line %d + +Warning: IntlTimeZone::getRegion(): intltz_get_region: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getRegion() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlTimeZone::getRegion(): intltz_get_region: bad arguments in %s on line %d +bool(false) + +Warning: IntlTimeZone::getRegion(): intltz_get_region: could not convert time zone id to UTF-16 in %s on line %d +bool(false) + +Warning: IntlTimeZone::getRegion(): intltz_get_region: Error obtaining region in %s on line %d +bool(false) diff --git a/ext/intl/tests/timezone_getTZDataVersion_error.phpt b/ext/intl/tests/timezone_getTZDataVersion_error.phpt new file mode 100644 index 0000000000..258b8807b7 --- /dev/null +++ b/ext/intl/tests/timezone_getTZDataVersion_error.phpt @@ -0,0 +1,18 @@ +--TEST-- +IntlTimeZone::getTZDataVersion(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +var_dump(IntlTimeZone::getTZDataVersion('foo')); + +--EXPECTF-- + +Warning: IntlTimeZone::getTZDataVersion() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::getTZDataVersion(): intltz_get_tz_data_version: bad arguments in %s on line %d +bool(false) diff --git a/ext/intl/tests/timezone_getTZData_basic.phpt b/ext/intl/tests/timezone_getTZData_basic.phpt new file mode 100644 index 0000000000..dea5b7c4b3 --- /dev/null +++ b/ext/intl/tests/timezone_getTZData_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +IntlTimeZone::getTZDataVersion: basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +print_R(IntlTimeZone::getTZDataVersion()); +echo "\n"; +print_R(intltz_get_tz_data_version()); +echo "\n"; +?> +==DONE== +--EXPECTF-- +20%d%s +20%d%s +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_hasSameRules_basic.phpt b/ext/intl/tests/timezone_hasSameRules_basic.phpt new file mode 100644 index 0000000000..55faaf760b --- /dev/null +++ b/ext/intl/tests/timezone_hasSameRules_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +IntlTimeZone::hasSameRules(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); +$prt = IntlTimeZone::createTimeZone('Portugal'); +$azo = IntlTimeZone::createTimeZone('Atlantic/Azores'); + +echo "Europe/Lisbon has same rules as itself:\n"; +var_dump($lsb->hasSameRules($lsb)); + +echo "\nEurope/Lisbon has same rules as Portugal:\n"; +var_dump($lsb->hasSameRules($prt)); + +echo "\nEurope/Lisbon has same rules as Atlantic/Azores:\n"; +var_dump(intltz_has_same_rules($lsb, $azo)); + +?> +==DONE== +--EXPECT-- +Europe/Lisbon has same rules as itself: +bool(true) + +Europe/Lisbon has same rules as Portugal: +bool(true) + +Europe/Lisbon has same rules as Atlantic/Azores: +bool(false) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_hasSameRules_error.phpt b/ext/intl/tests/timezone_hasSameRules_error.phpt new file mode 100644 index 0000000000..35a29be5db --- /dev/null +++ b/ext/intl/tests/timezone_hasSameRules_error.phpt @@ -0,0 +1,37 @@ +--TEST-- +IntlTimeZone::hasSameRules(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +function error_handler($errno, $errstr, $errfile, $errline) +{ + var_dump($errno, $errstr); + return true; +} +set_error_handler("error_handler"); + +$tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($tz->hasSameRules('foo')); + +var_dump(intltz_has_same_rules(null, $tz)); + +--EXPECT-- +int(4096) +string(99) "Argument 1 passed to IntlTimeZone::hasSameRules() must be an instance of IntlTimeZone, string given" +int(2) +string(81) "IntlTimeZone::hasSameRules() expects parameter 1 to be IntlTimeZone, string given" +int(2) +string(66) "IntlTimeZone::hasSameRules(): intltz_has_same_rules: bad arguments" +bool(false) +int(4096) +string(92) "Argument 1 passed to intltz_has_same_rules() must be an instance of IntlTimeZone, null given" +int(2) +string(74) "intltz_has_same_rules() expects parameter 1 to be IntlTimeZone, null given" +int(2) +string(61) "intltz_has_same_rules(): intltz_has_same_rules: bad arguments" +bool(false) diff --git a/ext/intl/tests/timezone_useDaylightTime_basic.phpt b/ext/intl/tests/timezone_useDaylightTime_basic.phpt new file mode 100644 index 0000000000..15baf108b3 --- /dev/null +++ b/ext/intl/tests/timezone_useDaylightTime_basic.phpt @@ -0,0 +1,25 @@ +--TEST-- +IntlTimeZone::useDaylightTime: basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); +$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon'); +$gmt = IntlTimeZone::getGMT(); + +var_dump($lsb->useDaylightTime()); +var_dump($gmt->useDaylightTime()); + +var_dump(intltz_use_daylight_time($lsb)); +var_dump(intltz_use_daylight_time($gmt)); +?> +==DONE== +--EXPECT-- +bool(true) +bool(false) +bool(true) +bool(false) +==DONE==
\ No newline at end of file diff --git a/ext/intl/tests/timezone_useDaylightTime_error.phpt b/ext/intl/tests/timezone_useDaylightTime_error.phpt new file mode 100644 index 0000000000..aa5ca6cfca --- /dev/null +++ b/ext/intl/tests/timezone_useDaylightTime_error.phpt @@ -0,0 +1,22 @@ +--TEST-- +IntlTimeZone::useDaylightTime(): errors +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); +var_dump($tz->useDaylightTime('foo')); +intltz_use_daylight_time(null); + +--EXPECTF-- + +Warning: IntlTimeZone::useDaylightTime() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlTimeZone::useDaylightTime(): intltz_use_daylight_time: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intltz_use_daylight_time() must be an instance of IntlTimeZone, null given in %s on line %d diff --git a/ext/intl/timezone/timezone_class.cpp b/ext/intl/timezone/timezone_class.cpp new file mode 100644 index 0000000000..5b8dfd2199 --- /dev/null +++ b/ext/intl/timezone/timezone_class.cpp @@ -0,0 +1,440 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <unicode/timezone.h> +#include <unicode/calendar.h> +#include "../intl_convertcpp.h" + +extern "C" { +#include "../intl_convert.h" +#define USE_TIMEZONE_POINTER 1 +#include "timezone_class.h" +#include "timezone_methods.h" +#include <zend_exceptions.h> +/* avoid redefinition of int8_t, already defined in unicode/pwin32.h */ +#define _MSC_STDINT_H_ 1 +#include <ext/date/php_date.h> +} + +/* {{{ Global variables */ +U_CDECL_BEGIN +zend_class_entry *TimeZone_ce_ptr = NULL; +zend_object_handlers TimeZone_handlers; +U_CDECL_END +/* }}} */ + +/* {{{ timezone_object_construct */ +U_CFUNC void timezone_object_construct(const TimeZone *zone, zval *object, int owned TSRMLS_DC) +{ + TimeZone_object *to; + + object_init_ex(object, TimeZone_ce_ptr); + TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK; /* fetch zend object from zval "object" into "to" */ + to->utimezone = zone; + to->should_delete = owned; +} +/* }}} */ + +/* {{{ timezone_process_timezone_argument + * TimeZone argument processor for constructor like functions (sets the global + * error). */ +TimeZone *timezone_process_timezone_argument(zval **zv_timezone, const char *func TSRMLS_DC) +{ + zval local_zv_tz = zval_used_for_init, + *local_zv_tz_p = &local_zv_tz; + char *message = NULL; + TimeZone *timeZone; + + if (zv_timezone == NULL || Z_TYPE_PP(zv_timezone) == IS_NULL) { + timelib_tzinfo *tzinfo = get_timezone_info(TSRMLS_C); + ZVAL_STRING(&local_zv_tz, tzinfo->name, 0); + zv_timezone = &local_zv_tz_p; + } + + if (Z_TYPE_PP(zv_timezone) == IS_OBJECT && + instanceof_function(Z_OBJCE_PP(zv_timezone), TimeZone_ce_ptr TSRMLS_CC)) { + TimeZone_object *to = (TimeZone_object*)zend_objects_get_address( + *zv_timezone TSRMLS_CC); + if (to->utimezone == NULL) { + spprintf(&message, 0, "%s: passed IntlTimeZone is not " + "properly constructed", func); + if (message) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); + efree(message); + } + return NULL; + } + timeZone = to->utimezone->clone(); + if (timeZone == NULL) { + spprintf(&message, 0, "%s: could not clone TimeZone", func); + if (message) { + intl_error_set(NULL, U_MEMORY_ALLOCATION_ERROR, message, 1 TSRMLS_CC); + efree(message); + } + return NULL; + } + } else { + UnicodeString id, + gottenId; + UErrorCode status = U_ZERO_ERROR; + convert_to_string_ex(zv_timezone); + if (intl_stringFromChar(id, Z_STRVAL_PP(zv_timezone), Z_STRLEN_PP(zv_timezone), + &status) == FAILURE) { + spprintf(&message, 0, "%s: Time zone identifier given is not a " + "valid UTF-8 string", func); + if (message) { + intl_error_set(NULL, status, message, 1 TSRMLS_CC); + efree(message); + } + return NULL; + } + timeZone = TimeZone::createTimeZone(id); + if (timeZone == NULL) { + spprintf(&message, 0, "%s: could not create time zone", func); + if (message) { + intl_error_set(NULL, U_MEMORY_ALLOCATION_ERROR, message, 1 TSRMLS_CC); + efree(message); + } + return NULL; + } + if (timeZone->getID(gottenId) != id) { + spprintf(&message, 0, "%s: no such time zone: '%s'", + func, Z_STRVAL_PP(zv_timezone)); + if (message) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); + efree(message); + } + delete timeZone; + return NULL; + } + } + + return timeZone; +} +/* }}} */ + +/* {{{ clone handler for TimeZone */ +static zend_object_value TimeZone_clone_obj(zval *object TSRMLS_DC) +{ + TimeZone_object *to_orig, + *to_new; + zend_object_value ret_val; + intl_error_reset(NULL TSRMLS_CC); + + to_orig = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC); + intl_error_reset(TIMEZONE_ERROR_P(to_orig) TSRMLS_CC); + + ret_val = TimeZone_ce_ptr->create_object(TimeZone_ce_ptr TSRMLS_CC); + to_new = (TimeZone_object*)zend_object_store_get_object_by_handle( + ret_val.handle TSRMLS_CC); + + zend_objects_clone_members(&to_new->zo, ret_val, + &to_orig->zo, Z_OBJ_HANDLE_P(object) TSRMLS_CC); + + if (to_orig->utimezone != NULL) { + TimeZone *newTimeZone; + + newTimeZone = to_orig->utimezone->clone(); + to_new->should_delete = 1; + if (!newTimeZone) { + char *err_msg; + intl_errors_set_code(TIMEZONE_ERROR_P(to_orig), + U_MEMORY_ALLOCATION_ERROR TSRMLS_CC); + intl_errors_set_custom_msg(TIMEZONE_ERROR_P(to_orig), + "Could not clone IntlTimeZone", 0 TSRMLS_CC); + err_msg = intl_error_get_message(TIMEZONE_ERROR_P(to_orig) TSRMLS_CC); + zend_throw_exception(NULL, err_msg, 0 TSRMLS_CC); + efree(err_msg); + } else { + to_new->utimezone = newTimeZone; + } + } else { + zend_throw_exception(NULL, "Cannot clone unconstructed IntlTimeZone", 0 TSRMLS_CC); + } + + return ret_val; +} +/* }}} */ + +/* {{{ compare_objects handler for TimeZone + * Can't be used for >, >=, <, <= comparisons */ +static int TimeZone_compare_objects(zval *object1, zval *object2 TSRMLS_DC) +{ + TimeZone_object *to1, + *to2; + to1 = (TimeZone_object*)zend_object_store_get_object(object1 TSRMLS_CC); + to2 = (TimeZone_object*)zend_object_store_get_object(object2 TSRMLS_CC); + + if (to1->utimezone == NULL || to2->utimezone == NULL) { + zend_throw_exception(NULL, "Comparison with at least one unconstructed " + "IntlTimeZone operand", 0 TSRMLS_CC); + /* intentionally not returning */ + } else { + if (*to1->utimezone == *to2->utimezone) { + return 0; + } + } + + return 1; +} +/* }}} */ + +/* {{{ get_debug_info handler for TimeZone */ +static HashTable *TimeZone_get_debug_info(zval *object, int *is_temp TSRMLS_DC) +{ + zval zv = zval_used_for_init; + TimeZone_object *to; + const TimeZone *tz; + UnicodeString ustr; + char *str; + int str_len; + UErrorCode uec = U_ZERO_ERROR; + + *is_temp = 1; + + array_init_size(&zv, 4); + + to = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC); + tz = to->utimezone; + + if (tz == NULL) { + add_assoc_bool_ex(&zv, "valid", sizeof("valid"), 0); + return Z_ARRVAL(zv); + } + + add_assoc_bool_ex(&zv, "valid", sizeof("valid"), 1); + + tz->getID(ustr); + intl_convert_utf16_to_utf8(&str, &str_len, + ustr.getBuffer(), ustr.length(), &uec); + if (U_FAILURE(uec)) { + return Z_ARRVAL(zv); + } + add_assoc_stringl_ex(&zv, "id", sizeof("id"), str, str_len, 0); + + int32_t rawOffset, dstOffset; + UDate now = Calendar::getNow(); + tz->getOffset(now, FALSE, rawOffset, dstOffset, uec); + if (U_FAILURE(uec)) { + return Z_ARRVAL(zv); + } + + add_assoc_long_ex(&zv, "rawOffset", sizeof("rawOffset"), (long)rawOffset); + add_assoc_long_ex(&zv, "currentOffset", sizeof("currentOffset"), + (long)(rawOffset + dstOffset)); + + *is_temp = 1; + + return Z_ARRVAL(zv); +} +/* }}} */ + +/* {{{ void TimeZone_object_init(TimeZone_object* to) + * Initialize internals of TImeZone_object not specific to zend standard objects. + */ +static void TimeZone_object_init(TimeZone_object *to TSRMLS_DC) +{ + intl_error_init(TIMEZONE_ERROR_P(to) TSRMLS_CC); + to->utimezone = NULL; + to->should_delete = 0; +} +/* }}} */ + +/* {{{ TimeZone_objects_dtor */ +static void TimeZone_objects_dtor(zend_object *object, + zend_object_handle handle TSRMLS_DC) +{ + zend_objects_destroy_object(object, handle TSRMLS_CC); +} +/* }}} */ + +/* {{{ TimeZone_objects_free */ +static void TimeZone_objects_free(zend_object *object TSRMLS_DC) +{ + TimeZone_object* to = (TimeZone_object*) object; + + if (to->utimezone && to->should_delete) { + delete to->utimezone; + to->utimezone = NULL; + } + intl_error_reset(TIMEZONE_ERROR_P(to) TSRMLS_CC); + + zend_object_std_dtor(&to->zo TSRMLS_CC); + + efree(to); +} +/* }}} */ + +/* {{{ TimeZone_object_create */ +static zend_object_value TimeZone_object_create(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value retval; + TimeZone_object* intern; + + intern = (TimeZone_object*)ecalloc(1, sizeof(TimeZone_object)); + + zend_object_std_init(&intern->zo, ce TSRMLS_CC); +#if PHP_VERSION_ID < 50399 + zend_hash_copy(intern->zo.properties, &(ce->default_properties), + (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); +#else + object_properties_init((zend_object*) intern, ce); +#endif + TimeZone_object_init(intern TSRMLS_CC); + + retval.handle = zend_objects_store_put( + intern, + (zend_objects_store_dtor_t) TimeZone_objects_dtor, + (zend_objects_free_object_storage_t) TimeZone_objects_free, + NULL TSRMLS_CC); + + retval.handlers = &TimeZone_handlers; + + return retval; +} +/* }}} */ + +/* {{{ TimeZone methods arguments info */ + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_idarg, 0, 0, 1) + ZEND_ARG_INFO(0, zoneId) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_createEnumeration, 0, 0, 0) + ZEND_ARG_INFO(0, countryOrRawOffset) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_countEquivalentIDs, 0, 0, 1) + ZEND_ARG_INFO(0, zoneId) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_createTimeZoneIDEnumeration, 0, 0, 1) + ZEND_ARG_INFO(0, zoneType) + ZEND_ARG_INFO(0, region) + ZEND_ARG_INFO(0, rawOffset) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getCanonicalID, 0, 0, 1) + ZEND_ARG_INFO(0, zoneId) + ZEND_ARG_INFO(1, isSystemID) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getEquivalentID, 0, 0, 2) + ZEND_ARG_INFO(0, zoneId) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getOffset, 0, 0, 4) + ZEND_ARG_INFO(0, date) + ZEND_ARG_INFO(0, local) + ZEND_ARG_INFO(1, rawOffset) + ZEND_ARG_INFO(1, dstOffset) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_hasSameRules, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, otherTimeZone, IntlTimeZone, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getDisplayName, 0, 0, 0) + ZEND_ARG_INFO(0, isDaylight) + ZEND_ARG_INFO(0, style) + ZEND_ARG_INFO(0, locale) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_void, 0, 0, 0) +ZEND_END_ARG_INFO() + +/* }}} */ + +/* {{{ TimeZone_class_functions + * Every 'IntlTimeZone' class method has an entry in this table + */ +static zend_function_entry TimeZone_class_functions[] = { + PHP_ME_MAPPING(createTimeZone, intltz_create_time_zone, ainfo_tz_idarg, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(createDefault, intltz_create_default, ainfo_tz_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(getGMT, intltz_get_gmt, ainfo_tz_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(createEnumeration, intltz_create_enumeration, ainfo_tz_createEnumeration, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(countEquivalentIDs, intltz_count_equivalent_ids, ainfo_tz_idarg, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(createTimeZoneIDEnumeration, intltz_create_time_zone_id_enumeration, ainfo_tz_createTimeZoneIDEnumeration, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(getCanonicalID, intltz_get_canonical_id, ainfo_tz_getCanonicalID, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(getRegion, intltz_get_region, ainfo_tz_idarg, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(getTZDataVersion, intltz_get_tz_data_version, ainfo_tz_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(getEquivalentID, intltz_get_equivalent_id, ainfo_tz_getEquivalentID, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + + PHP_ME_MAPPING(getID, intltz_get_id, ainfo_tz_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(useDaylightTime, intltz_use_daylight_time, ainfo_tz_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getOffset, intltz_get_offset, ainfo_tz_getOffset, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getRawOffset, intltz_get_raw_offset, ainfo_tz_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(hasSameRules, intltz_has_same_rules, ainfo_tz_hasSameRules, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getDisplayName, intltz_get_display_name, ainfo_tz_getDisplayName, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getDSTSavings, intltz_get_dst_savings, ainfo_tz_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getErrorCode, intltz_get_error_code, ainfo_tz_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getErrorMessage, intltz_get_error_message, ainfo_tz_void, ZEND_ACC_PUBLIC) + PHP_FE_END +}; +/* }}} */ + +/* {{{ timezone_register_IntlTimeZone_class + * Initialize 'IntlTimeZone' class + */ +U_CFUNC void timezone_register_IntlTimeZone_class(TSRMLS_D) +{ + zend_class_entry ce; + + /* Create and register 'IntlTimeZone' class. */ + INIT_CLASS_ENTRY(ce, "IntlTimeZone", TimeZone_class_functions); + ce.create_object = TimeZone_object_create; + TimeZone_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC); + if (!TimeZone_ce_ptr) { + //can't happen now without bigger problems before + php_error_docref0(NULL TSRMLS_CC, E_ERROR, + "IntlTimeZone: class registration has failed."); + return; + } + + memcpy(&TimeZone_handlers, zend_get_std_object_handlers(), + sizeof TimeZone_handlers); + TimeZone_handlers.clone_obj = TimeZone_clone_obj; + TimeZone_handlers.compare_objects = TimeZone_compare_objects; + TimeZone_handlers.get_debug_info = TimeZone_get_debug_info; + + /* Declare 'IntlTimeZone' class constants */ +#define TIMEZONE_DECL_LONG_CONST(name, val) \ + zend_declare_class_constant_long(TimeZone_ce_ptr, name, sizeof(name) - 1, \ + val TSRMLS_CC) + + TIMEZONE_DECL_LONG_CONST("DISPLAY_SHORT", TimeZone::SHORT); + TIMEZONE_DECL_LONG_CONST("DISPLAY_LONG", TimeZone::LONG); + TIMEZONE_DECL_LONG_CONST("DISPLAY_SHORT_GENERIC", TimeZone::SHORT_GENERIC); + TIMEZONE_DECL_LONG_CONST("DISPLAY_LONG_GENERIC", TimeZone::LONG_GENERIC); + TIMEZONE_DECL_LONG_CONST("DISPLAY_SHORT_GMT", TimeZone::SHORT_GMT); + TIMEZONE_DECL_LONG_CONST("DISPLAY_LONG_GMT", TimeZone::LONG_GMT); + TIMEZONE_DECL_LONG_CONST("DISPLAY_SHORT_COMMONLY_USED", TimeZone::SHORT_COMMONLY_USED); + TIMEZONE_DECL_LONG_CONST("DISPLAY_GENERIC_LOCATION", TimeZone::GENERIC_LOCATION); + + TIMEZONE_DECL_LONG_CONST("TYPE_ANY", UCAL_ZONE_TYPE_ANY); + TIMEZONE_DECL_LONG_CONST("TYPE_CANONICAL", UCAL_ZONE_TYPE_CANONICAL); + TIMEZONE_DECL_LONG_CONST("TYPE_CANONICAL_LOCATION", UCAL_ZONE_TYPE_CANONICAL_LOCATION); + + /* Declare 'IntlTimeZone' class properties */ + +} +/* }}} */ diff --git a/ext/intl/timezone/timezone_class.h b/ext/intl/timezone/timezone_class.h new file mode 100644 index 0000000000..a239a18b67 --- /dev/null +++ b/ext/intl/timezone/timezone_class.h @@ -0,0 +1,68 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@netcabo.pt> | + +----------------------------------------------------------------------+ + */ + +#ifndef TIMEZONE_CLASS_H +#define TIMEZONE_CLASS_H + +//redefinition of inline in PHP headers causes problems, so include this before +#include <math.h> + +#include <php.h> +#include "intl_error.h" +#include "intl_data.h" + +#ifndef USE_TIMEZONE_POINTER +typedef void TimeZone; +#endif + +typedef struct { + zend_object zo; + + // error handling + intl_error err; + + // ICU TimeZone + const TimeZone *utimezone; + + //whether to delete the timezone on object free + zend_bool should_delete; +} TimeZone_object; + +#define TIMEZONE_ERROR(to) (to)->err +#define TIMEZONE_ERROR_P(to) &(TIMEZONE_ERROR(to)) + +#define TIMEZONE_ERROR_CODE(co) INTL_ERROR_CODE(TIMEZONE_ERROR(to)) +#define TIMEZONE_ERROR_CODE_P(co) &(INTL_ERROR_CODE(TIMEZONE_ERROR(to))) + +#define TIMEZONE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(TimeZone, to) +#define TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(TimeZone, to) +#define TIMEZONE_METHOD_FETCH_OBJECT\ + TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK; \ + if (to->utimezone == NULL) { \ + intl_errors_set(&to->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlTimeZone", 0 TSRMLS_CC); \ + RETURN_FALSE; \ + } + +TimeZone *timezone_process_timezone_argument(zval **zv_timezone, const char *func TSRMLS_DC); + +void timezone_object_construct(const TimeZone *zone, zval *object, int owned TSRMLS_DC); + +void timezone_register_IntlTimeZone_class(TSRMLS_D); + +extern zend_class_entry *TimeZone_ce_ptr; +extern zend_object_handlers TimeZone_handlers; + +#endif /* #ifndef TIMEZONE_CLASS_H */ diff --git a/ext/intl/timezone/timezone_methods.cpp b/ext/intl/timezone/timezone_methods.cpp new file mode 100644 index 0000000000..a6de82de24 --- /dev/null +++ b/ext/intl/timezone/timezone_methods.cpp @@ -0,0 +1,572 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <unicode/locid.h> +#include <unicode/timezone.h> +#include <unicode/ustring.h> +#include "intl_convertcpp.h" +extern "C" { +#define USE_TIMEZONE_POINTER 1 +#include "timezone_class.h" +#include "intl_convert.h" +#include "../locale/locale.h" +#include <zend_exceptions.h> +} +#include "common/common_enum.h" + +U_CFUNC PHP_FUNCTION(intltz_create_time_zone) +{ + char *str_id; + int str_id_len; + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", + &str_id, &str_id_len) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_create_time_zone: bad arguments", 0 TSRMLS_CC); + RETURN_NULL(); + } + + UErrorCode status = UErrorCode(); + UnicodeString id = UnicodeString(); + if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) { + intl_error_set(NULL, status, + "intltz_create_time_zone: could not convert time zone id to UTF-16", 0 TSRMLS_CC); + RETURN_NULL(); + } + + //guaranteed non-null; GMT if timezone cannot be understood + TimeZone *tz = TimeZone::createTimeZone(id); + timezone_object_construct(tz, return_value, 1 TSRMLS_CC); +} + +U_CFUNC PHP_FUNCTION(intltz_create_default) +{ + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_create_default: bad arguments", 0 TSRMLS_CC); + RETURN_NULL(); + } + + TimeZone *tz = TimeZone::createDefault(); + timezone_object_construct(tz, return_value, 1 TSRMLS_CC); +} + +U_CFUNC PHP_FUNCTION(intltz_get_gmt) +{ + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_gmt: bad arguments", 0 TSRMLS_CC); + RETURN_NULL(); + } + + timezone_object_construct(TimeZone::getGMT(), return_value, 0 TSRMLS_CC); +} + + +U_CFUNC PHP_FUNCTION(intltz_create_enumeration) +{ + zval **arg = NULL; + StringEnumeration *se = NULL; + intl_error_reset(NULL TSRMLS_CC); + + /* double indirection to have the zend engine destroy the new zval that + * results from separation */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|Z", &arg) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_create_enumeration: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (arg == NULL || Z_TYPE_PP(arg) == IS_NULL) { + se = TimeZone::createEnumeration(); + } else if (Z_TYPE_PP(arg) == IS_LONG) { +int_offset: + if (Z_LVAL_PP(arg) < (long)INT32_MIN || + Z_LVAL_PP(arg) > (long)INT32_MAX) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_create_enumeration: value is out of range", 0 TSRMLS_CC); + RETURN_FALSE; + } else { + se = TimeZone::createEnumeration((int32_t) Z_LVAL_PP(arg)); + } + } else if (Z_TYPE_PP(arg) == IS_DOUBLE) { +double_offset: + convert_to_long_ex(arg); + goto int_offset; + } else if (Z_TYPE_PP(arg) == IS_OBJECT || Z_TYPE_PP(arg) == IS_STRING) { + long lval; + double dval; + convert_to_string_ex(arg); + switch (is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &lval, &dval, 0)) { + case IS_DOUBLE: + SEPARATE_ZVAL(arg); + zval_dtor(*arg); + Z_TYPE_PP(arg) = IS_DOUBLE; + Z_DVAL_PP(arg) = dval; + goto double_offset; + case IS_LONG: + SEPARATE_ZVAL(arg); + zval_dtor(*arg); + Z_TYPE_PP(arg) = IS_LONG; + Z_LVAL_PP(arg) = lval; + goto int_offset; + } + /* else call string version */ + se = TimeZone::createEnumeration(Z_STRVAL_PP(arg)); + } else { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_create_enumeration: invalid argument type", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (se) { + IntlIterator_from_StringEnumeration(se, return_value TSRMLS_CC); + } else { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_create_enumeration: error obtaining enumeration", 0 TSRMLS_CC); + RETVAL_FALSE; + } +} + +U_CFUNC PHP_FUNCTION(intltz_count_equivalent_ids) +{ + char *str_id; + int str_id_len; + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", + &str_id, &str_id_len) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_count_equivalent_ids: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + UErrorCode status = UErrorCode(); + UnicodeString id = UnicodeString(); + if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) { + intl_error_set(NULL, status, + "intltz_count_equivalent_ids: could not convert time zone id to UTF-16", 0 TSRMLS_CC); + RETURN_FALSE; + } + + int32_t result = TimeZone::countEquivalentIDs(id); + RETURN_LONG((long)result); +} + +U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration) +{ + long zoneType, + offset_arg; + char *region = NULL; + int region_len = 0; + int32_t offset, + *offsetp = NULL; + int arg3isnull = 0; + intl_error_reset(NULL TSRMLS_CC); + + /* must come before zpp because zpp would convert the arg in the stack to 0 */ + if (ZEND_NUM_ARGS() == 3) { + zval **dummy, **zvoffset; + arg3isnull = zend_get_parameters_ex(3, &dummy, &dummy, &zvoffset) + != FAILURE && Z_TYPE_PP(zvoffset) == IS_NULL; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|s!l", + &zoneType, ®ion, ®ion_len, &offset_arg) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_create_time_zone_id_enumeration: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (zoneType != UCAL_ZONE_TYPE_ANY && zoneType != UCAL_ZONE_TYPE_CANONICAL + && zoneType != UCAL_ZONE_TYPE_CANONICAL_LOCATION) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_create_time_zone_id_enumeration: bad zone type", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (ZEND_NUM_ARGS() == 3) { + if (offset_arg < (long)INT32_MIN || offset_arg > (long)INT32_MAX) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_create_time_zone_id_enumeration: offset out of bounds", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (!arg3isnull) { + offset = (int32_t)offset_arg; + offsetp = &offset; + } //else leave offsetp NULL + } + + StringEnumeration *se; + UErrorCode uec = UErrorCode(); + se = TimeZone::createTimeZoneIDEnumeration((USystemTimeZoneType)zoneType, + region, offsetp, uec); + INTL_CHECK_STATUS(uec, "intltz_create_time_zone_id_enumeration: " + "Error obtaining time zone id enumeration") + + IntlIterator_from_StringEnumeration(se, return_value TSRMLS_CC); +} + +U_CFUNC PHP_FUNCTION(intltz_get_canonical_id) +{ + char *str_id; + int str_id_len; + zval *is_systemid = NULL; + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", + &str_id, &str_id_len, &is_systemid) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_canonical_id: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + UErrorCode status = UErrorCode(); + UnicodeString id; + if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) { + intl_error_set(NULL, status, + "intltz_get_canonical_id: could not convert time zone id to UTF-16", 0 TSRMLS_CC); + RETURN_FALSE; + } + + UnicodeString result; + UBool isSystemID; + TimeZone::getCanonicalID(id, result, isSystemID, status); + INTL_CHECK_STATUS(status, "intltz_get_canonical_id: error obtaining canonical ID"); + + intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), + result.getBuffer(), result.length(), &status); + INTL_CHECK_STATUS(status, + "intltz_get_canonical_id: could not convert time zone id to UTF-16"); + Z_TYPE_P(return_value) = IS_STRING; + + if (is_systemid) { /* by-ref argument passed */ + zval_dtor(is_systemid); + ZVAL_BOOL(is_systemid, isSystemID); + } +} + +U_CFUNC PHP_FUNCTION(intltz_get_region) +{ + char *str_id; + int str_id_len; + char outbuf[3]; + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", + &str_id, &str_id_len) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_region: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + UErrorCode status = UErrorCode(); + UnicodeString id; + if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) { + intl_error_set(NULL, status, + "intltz_get_region: could not convert time zone id to UTF-16", 0 TSRMLS_CC); + RETURN_FALSE; + } + + int32_t region_len = TimeZone::getRegion(id, outbuf, sizeof(outbuf), status); + INTL_CHECK_STATUS(status, "intltz_get_region: Error obtaining region"); + + RETURN_STRINGL(outbuf, region_len, 1); +} + +U_CFUNC PHP_FUNCTION(intltz_get_tz_data_version) +{ + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_tz_data_version: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + UErrorCode status = UErrorCode(); + const char *res = TimeZone::getTZDataVersion(status); + INTL_CHECK_STATUS(status, "intltz_get_tz_data_version: " + "Error obtaining time zone data version"); + + RETURN_STRING(res, 1); +} + +U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id) +{ + char *str_id; + int str_id_len; + long index; + intl_error_reset(NULL TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", + &str_id, &str_id_len, &index) == FAILURE || + index < (long)INT32_MIN || index > (long)INT32_MAX) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_equivalent_id: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + UErrorCode status = UErrorCode(); + UnicodeString id; + if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) { + intl_error_set(NULL, status, + "intltz_get_equivalent_id: could not convert time zone id to UTF-16", 0 TSRMLS_CC); + RETURN_FALSE; + } + + const UnicodeString result = TimeZone::getEquivalentID(id, (int32_t)index); + intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), + result.getBuffer(), result.length(), &status); + INTL_CHECK_STATUS(status, "intltz_get_equivalent_id: " + "could not convert resulting time zone id to UTF-16"); + Z_TYPE_P(return_value) = IS_STRING; +} + +U_CFUNC PHP_FUNCTION(intltz_get_id) +{ + TIMEZONE_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + &object, TimeZone_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_id: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + TIMEZONE_METHOD_FETCH_OBJECT; + + UnicodeString id_us; + to->utimezone->getID(id_us); + + char *id = NULL; + int id_len = 0; + + intl_convert_utf16_to_utf8(&id, &id_len, + id_us.getBuffer(), id_us.length(), TIMEZONE_ERROR_CODE_P(to)); + INTL_METHOD_CHECK_STATUS(to, "intltz_get_id: Could not convert id to UTF-8"); + + RETURN_STRINGL(id, id_len, 0); +} + +U_CFUNC PHP_FUNCTION(intltz_use_daylight_time) +{ + TIMEZONE_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + &object, TimeZone_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_use_daylight_time: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + TIMEZONE_METHOD_FETCH_OBJECT; + + RETURN_BOOL(to->utimezone->useDaylightTime()); +} + +U_CFUNC PHP_FUNCTION(intltz_get_offset) +{ + UDate date; + zend_bool local; + zval *rawOffsetArg, + *dstOffsetArg; + int32_t rawOffset, + dstOffset; + TIMEZONE_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Odbzz", &object, TimeZone_ce_ptr, &date, &local, &rawOffsetArg, + &dstOffsetArg) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_offset: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + TIMEZONE_METHOD_FETCH_OBJECT; + + to->utimezone->getOffset(date, (UBool) local, rawOffset, dstOffset, + TIMEZONE_ERROR_CODE(to)); + + INTL_METHOD_CHECK_STATUS(to, "intltz_get_offset: error obtaining offset"); + + zval_dtor(rawOffsetArg); + ZVAL_LONG(rawOffsetArg, rawOffset); + zval_dtor(dstOffsetArg); + ZVAL_LONG(dstOffsetArg, dstOffset); + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intltz_get_raw_offset) +{ + TIMEZONE_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O", &object, TimeZone_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_raw_offset: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + TIMEZONE_METHOD_FETCH_OBJECT; + + RETURN_LONG(to->utimezone->getRawOffset()); +} + +U_CFUNC PHP_FUNCTION(intltz_has_same_rules) +{ + zval *other_object; + TimeZone_object *other_to; + TIMEZONE_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "OO", &object, TimeZone_ce_ptr, &other_object, TimeZone_ce_ptr) + == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_has_same_rules: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + TIMEZONE_METHOD_FETCH_OBJECT; + other_to = (TimeZone_object *) zend_object_store_get_object(other_object TSRMLS_CC); + if (other_to->utimezone == NULL) { + intl_errors_set(&to->err, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_has_same_rules: The second IntlTimeZone is unconstructed", 0 TSRMLS_CC); + RETURN_FALSE; + } + + RETURN_BOOL(to->utimezone->hasSameRules(*other_to->utimezone)); +} + +static const TimeZone::EDisplayType display_types[] = { + TimeZone::SHORT, TimeZone::LONG, + TimeZone::SHORT_GENERIC, TimeZone::LONG_GENERIC, + TimeZone::SHORT_GMT, TimeZone::LONG_GMT, + TimeZone::SHORT_COMMONLY_USED, TimeZone::GENERIC_LOCATION +}; + +U_CFUNC PHP_FUNCTION(intltz_get_display_name) +{ + zend_bool daylight = 0; + long display_type = TimeZone::LONG; + const char *locale_str = NULL; + int dummy = 0; + TIMEZONE_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O|bls!", &object, TimeZone_ce_ptr, &daylight, &display_type, + &locale_str, &dummy) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_display_name: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + bool found = false; + for (int i = 0; !found && i < sizeof(display_types)/sizeof(*display_types); i++) { + if (display_types[i] == display_type) + found = true; + } + if (!found) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_display_name: wrong display type", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (!locale_str) { + locale_str = intl_locale_get_default(TSRMLS_C); + } + + TIMEZONE_METHOD_FETCH_OBJECT; + + UnicodeString result; + to->utimezone->getDisplayName((UBool)daylight, (TimeZone::EDisplayType)display_type, + Locale::createFromName(locale_str), result); + + intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), + result.getBuffer(), result.length(), TIMEZONE_ERROR_CODE_P(to)); + INTL_METHOD_CHECK_STATUS(to, "intltz_get_display_name: " + "could not convert resulting time zone id to UTF-16"); + + Z_TYPE_P(return_value) = IS_STRING; +} + +U_CFUNC PHP_FUNCTION(intltz_get_dst_savings) +{ + TIMEZONE_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "O", &object, TimeZone_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_dst_savings: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + TIMEZONE_METHOD_FETCH_OBJECT; + + RETURN_LONG((long)to->utimezone->getDSTSavings()); +} + +U_CFUNC PHP_FUNCTION(intltz_get_error_code) +{ + TIMEZONE_METHOD_INIT_VARS + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + &object, TimeZone_ce_ptr) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_error_code: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + /* Fetch the object (without resetting its last error code ). */ + to = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC); + if (to == NULL) + RETURN_FALSE; + + RETURN_LONG((long)TIMEZONE_ERROR_CODE(to)); +} + +U_CFUNC PHP_FUNCTION(intltz_get_error_message) +{ + const char* message = NULL; + TIMEZONE_METHOD_INIT_VARS + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + &object, TimeZone_ce_ptr) == FAILURE) { + intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_error_message: bad arguments", 0 TSRMLS_CC ); + RETURN_FALSE; + } + + + /* Fetch the object (without resetting its last error code ). */ + to = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC); + if (to == NULL) + RETURN_FALSE; + + /* Return last error message. */ + message = intl_error_get_message(TIMEZONE_ERROR_P(to) TSRMLS_CC); + RETURN_STRING(message, 0); +} diff --git a/ext/intl/timezone/timezone_methods.h b/ext/intl/timezone/timezone_methods.h new file mode 100644 index 0000000000..b16881209b --- /dev/null +++ b/ext/intl/timezone/timezone_methods.h @@ -0,0 +1,60 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@netcabo.pt> | + +----------------------------------------------------------------------+ + */ + +#ifndef TIMEZONE_METHODS_H +#define TIMEZONE_METHODS_H + +#include <php.h> + +PHP_FUNCTION(intltz_create_time_zone); + +PHP_FUNCTION(intltz_create_default); + +PHP_FUNCTION(intltz_get_id); + +PHP_FUNCTION(intltz_get_gmt); + +PHP_FUNCTION(intltz_create_enumeration); + +PHP_FUNCTION(intltz_count_equivalent_ids); + +PHP_FUNCTION(intltz_create_time_zone_id_enumeration); + +PHP_FUNCTION(intltz_get_canonical_id); + +PHP_FUNCTION(intltz_get_region); + +PHP_FUNCTION(intltz_get_tz_data_version); + +PHP_FUNCTION(intltz_get_equivalent_id); + +PHP_FUNCTION(intltz_use_daylight_time); + +PHP_FUNCTION(intltz_get_offset); + +PHP_FUNCTION(intltz_get_raw_offset); + +PHP_FUNCTION(intltz_has_same_rules); + +PHP_FUNCTION(intltz_get_display_name); + +PHP_FUNCTION(intltz_get_dst_savings); + +PHP_FUNCTION(intltz_get_error_code); + +PHP_FUNCTION(intltz_get_error_message); + +#endif /* #ifndef TIMEZONE_METHODS_H */ |