com php-src: Supported Calendar methods new to ICU 49.: ext/intl/calendar/calendar_class.cpp ext/intl/calendar/ca lendar_methods.cpp
ext/intl/calendar/calendar_methods .h ext/intl/php_intl.c ext/intl/tests/calendar_getS kipped_RepeatedWallTimeOption_error.phpt ext/intl/tests
/calendar_get_setRepeatedWallTimeOption_basic.phpt ex t/intl/tests/calendar_get_setSkippedWallTimeOption_basic .phpt
ext/intl/tests/calendar_setSkipped_RepeatedWallTi meOption_error

From: Date: Sun, 01 Apr 2012 13:37:07 +0000
Subject: com php-src: Supported Calendar methods new to ICU 49.: ext/intl/calendar/calendar_class.cpp ext/intl/calendar/ca lendar_methods.cpp
ext/intl/calendar/calendar_methods .h ext/intl/php_intl.c ext/intl/tests/calendar_getS kipped_RepeatedWallTimeOption_error.phpt ext/intl/tests
/calendar_get_setRepeatedWallTimeOption_basic.phpt ex t/intl/tests/calendar_get_setSkippedWallTimeOption_basic .phpt
ext/intl/tests/calendar_setSkipped_RepeatedWallTi meOption_error
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-68627@lists.php.net to get a copy of this message
Commit: d3a29c108bf146440645d8b1a3b2e0f22a34ac59 Author: Gustavo André dos Santos Lopes <cataphract@php.net> Sun, 1 Apr 2012 15:37:07 +0200 Parents: 7460741f991aa646e54456ef022676ca184b54fe Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d3a29c108bf146440645d8b1a3b2e0f22a34ac59 Log: Supported Calendar methods new to ICU 49. Changed paths: M ext/intl/calendar/calendar_class.cpp M ext/intl/calendar/calendar_methods.cpp M ext/intl/calendar/calendar_methods.h M ext/intl/php_intl.c A ext/intl/tests/calendar_getSkipped_RepeatedWallTimeOption_error.phpt A ext/intl/tests/calendar_get_setRepeatedWallTimeOption_basic.phpt A ext/intl/tests/calendar_get_setSkippedWallTimeOption_basic.phpt A ext/intl/tests/calendar_setSkipped_RepeatedWallTimeOption_error.phpt

diff --git a/ext/intl/calendar/calendar_class.cpp b/ext/intl/calendar/calendar_class.cpp index d4c4828..c411962 100644 --- a/ext/intl/calendar/calendar_class.cpp +++ b/ext/intl/calendar/calendar_class.cpp @@ -351,6 +351,10 @@ ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_setLenient, 0, 0, 1) ZEND_ARG_INFO(0, isLenient) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_wall_time_option, 0, 0, 1) + ZEND_ARG_INFO(0, wallTimeOption) +ZEND_END_ARG_INFO() + /* Gregorian Calendar */ ZEND_BEGIN_ARG_INFO_EX(ainfo_gregcal___construct, 0, 0, 0) ZEND_ARG_INFO(0, timeZoneOrYear) @@ -408,6 +412,12 @@ static const zend_function_entry Calendar_class_functions[] = { 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) +#if U_ICU_VERSION_MAJOR_NUM >= 49 + PHP_ME_MAPPING(getRepeatedWallTimeOption,intlcal_get_repeated_wall_time_option,ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(getSkippedWallTimeOption,intlcal_get_skipped_wall_time_option,ainfo_cal_void, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(setRepeatedWallTimeOption,intlcal_set_repeated_wall_time_option,ainfo_cal_wall_time_option,ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(setSkippedWallTimeOption,intlcal_set_skipped_wall_time_option,ainfo_cal_wall_time_option,ZEND_ACC_PUBLIC) +#endif 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 @@ -505,5 +515,10 @@ void calendar_register_IntlCalendar_class(TSRMLS_D) CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_OFFSET", UCAL_WEEKEND_ONSET); CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_CEASE", UCAL_WEEKEND_CEASE); +#if U_ICU_VERSION_MAJOR_NUM >= 49 + CALENDAR_DECL_LONG_CONST("WALLTIME_FIRST", UCAL_WALLTIME_FIRST); + CALENDAR_DECL_LONG_CONST("WALLTIME_LAST", UCAL_WALLTIME_LAST); + CALENDAR_DECL_LONG_CONST("WALLTIME_NEXT_VALID", UCAL_WALLTIME_NEXT_VALID); +#endif } /* }}} */ diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index 5eb0c13..d84ad65 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -1019,6 +1019,93 @@ U_CFUNC PHP_FUNCTION(intlcal_equals) RETURN_BOOL((int)result); } +#if U_ICU_VERSION_MAJOR_NUM >= 49 + +U_CFUNC PHP_FUNCTION(intlcal_get_repeated_wall_time_option) +{ + 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_repeated_wall_time_option: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + RETURN_LONG(co->ucal->getRepeatedWallTimeOption()); +} + +U_CFUNC PHP_FUNCTION(intlcal_get_skipped_wall_time_option) +{ + 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_skipped_wall_time_option: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + RETURN_LONG(co->ucal->getSkippedWallTimeOption()); +} + +U_CFUNC PHP_FUNCTION(intlcal_set_repeated_wall_time_option) +{ + long option; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, Calendar_ce_ptr, &option) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_repeated_wall_time_option: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (option != UCAL_WALLTIME_FIRST && option != UCAL_WALLTIME_LAST) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_repeated_wall_time_option: invalid option", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + co->ucal->setRepeatedWallTimeOption((UCalendarWallTimeOption)option); + + RETURN_TRUE; +} + +U_CFUNC PHP_FUNCTION(intlcal_set_skipped_wall_time_option) +{ + long option; + CALENDAR_METHOD_INIT_VARS; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), + "Ol", &object, Calendar_ce_ptr, &option) == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_skipped_wall_time_option: bad arguments", 0 TSRMLS_CC); + RETURN_FALSE; + } + + if (option != UCAL_WALLTIME_FIRST && option != UCAL_WALLTIME_LAST + && option != UCAL_WALLTIME_NEXT_VALID) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlcal_set_skipped_wall_time_option: invalid option", 0 TSRMLS_CC); + RETURN_FALSE; + } + + CALENDAR_METHOD_FETCH_OBJECT; + + co->ucal->setSkippedWallTimeOption((UCalendarWallTimeOption)option); + + RETURN_TRUE; +} + +#endif + U_CFUNC PHP_FUNCTION(intlcal_get_error_code) { CALENDAR_METHOD_INIT_VARS; diff --git a/ext/intl/calendar/calendar_methods.h b/ext/intl/calendar/calendar_methods.h index 93aaa38..95ff537 100644 --- a/ext/intl/calendar/calendar_methods.h +++ b/ext/intl/calendar/calendar_methods.h @@ -93,6 +93,14 @@ PHP_FUNCTION(intlcal_set_lenient); PHP_FUNCTION(intlcal_equals); +PHP_FUNCTION(intlcal_get_repeated_wall_time_option); + +PHP_FUNCTION(intlcal_get_skipped_wall_time_option); + +PHP_FUNCTION(intlcal_set_repeated_wall_time_option); + +PHP_FUNCTION(intlcal_set_skipped_wall_time_option); + PHP_FUNCTION(intlcal_get_error_code); PHP_FUNCTION(intlcal_get_error_message); diff --git a/ext/intl/php_intl.c b/ext/intl/php_intl.c index 54b1e76..9504555 100755 --- a/ext/intl/php_intl.c +++ b/ext/intl/php_intl.c @@ -556,6 +556,11 @@ ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_set_lenient, 0, 0, 2 ) ZEND_ARG_INFO( 0, isLenient ) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX( ainfo_cal_wall_time_option, 0, 0, 2 ) + ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 ) + ZEND_ARG_INFO( 0, wallTimeOption ) +ZEND_END_ARG_INFO() + /* Gregorian Calendar */ ZEND_BEGIN_ARG_INFO_EX( ainfo_gregcal_create_instance, 0, 0, 0 ) ZEND_ARG_INFO(0, timeZoneOrYear) @@ -765,6 +770,12 @@ zend_function_entry intl_functions[] = { 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 ) +#if U_ICU_VERSION_MAJOR_NUM >= 49 + PHP_FE( intlcal_get_repeated_wall_time_option, ainfo_cal_only_cal ) + PHP_FE( intlcal_get_skipped_wall_time_option, ainfo_cal_only_cal ) + PHP_FE( intlcal_set_repeated_wall_time_option, ainfo_cal_wall_time_option ) + PHP_FE( intlcal_set_skipped_wall_time_option, ainfo_cal_wall_time_option ) +#endif PHP_FE( intlcal_get_error_code, ainfo_cal_only_cal ) PHP_FE( intlcal_get_error_message, ainfo_cal_only_cal ) diff --git a/ext/intl/tests/calendar_getSkipped_RepeatedWallTimeOption_error.phpt b/ext/intl/tests/calendar_getSkipped_RepeatedWallTimeOption_error.phpt new file mode 100644 index 0000000..f632cbf --- /dev/null +++ b/ext/intl/tests/calendar_getSkipped_RepeatedWallTimeOption_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +IntlCalendar::getSkipped/RepeatedWallTimeOption(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +if (version_compare(INTL_ICU_VERSION, '49') < 0) + die('skip for ICU 49+'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->getSkippedWallTimeOption(1)); +var_dump($c->getRepeatedWallTimeOption(1)); + +var_dump(intlcal_get_skipped_wall_time_option($c, 1)); +var_dump(intlcal_get_repeated_wall_time_option($c, 1)); + +var_dump(intlcal_get_skipped_wall_time_option(1)); + +--EXPECTF-- + +Warning: IntlCalendar::getSkippedWallTimeOption() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getSkippedWallTimeOption(): intlcal_get_skipped_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::getRepeatedWallTimeOption() expects exactly 0 parameters, 1 given in %s on line %d + +Warning: IntlCalendar::getRepeatedWallTimeOption(): intlcal_get_repeated_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_get_skipped_wall_time_option() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlcal_get_skipped_wall_time_option(): intlcal_get_skipped_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_get_repeated_wall_time_option() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: intlcal_get_repeated_wall_time_option(): intlcal_get_repeated_wall_time_option: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_get_skipped_wall_time_option() must be an instance of IntlCalendar, integer given in %s on line %d diff --git a/ext/intl/tests/calendar_get_setRepeatedWallTimeOption_basic.phpt b/ext/intl/tests/calendar_get_setRepeatedWallTimeOption_basic.phpt new file mode 100644 index 0000000..5276543 --- /dev/null +++ b/ext/intl/tests/calendar_get_setRepeatedWallTimeOption_basic.phpt @@ -0,0 +1,49 @@ +--TEST-- +IntlCalendar::get/setRepeatedWallTimeOption(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +if (version_compare(INTL_ICU_VERSION, '49') < 0) + die('skip for ICU 49+'); +--FILE-- + +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +date_default_timezone_set('Europe/Amsterdam'); + +//28 October 2012, transition from DST +$intlcal = new IntlGregorianCalendar(2012, 9, 28, 0, 0, 0); +var_dump($intlcal->setRepeatedWallTimeOption(IntlCalendar::WALLTIME_LAST)); +var_dump($intlcal->getRepeatedWallTimeOption()); +$intlcal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 2); +$intlcal->set(IntlCalendar::FIELD_MINUTE, 30); +var_dump( + strtotime('2012-10-28 02:30:00 +0100'), + (int)($intlcal->getTime() /1000) +); + +var_dump(intlcal_set_repeated_wall_time_option($intlcal, IntlCalendar::WALLTIME_FIRST)); +var_dump(intlcal_get_repeated_wall_time_option($intlcal)); +$intlcal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 2); +$intlcal->set(IntlCalendar::FIELD_MINUTE, 30); +var_dump( + strtotime('2012-10-28 02:30:00 +0200'), + (int)($intlcal->getTime() /1000) +); + +?> +==DONE== +--EXPECT-- + +bool(true) +int(0) +int(1351387800) +int(1351387800) +bool(true) +int(1) +int(1351384200) +int(1351384200) +==DONE== \ No newline at end of file diff --git a/ext/intl/tests/calendar_get_setSkippedWallTimeOption_basic.phpt b/ext/intl/tests/calendar_get_setSkippedWallTimeOption_basic.phpt new file mode 100644 index 0000000..bbbf031 --- /dev/null +++ b/ext/intl/tests/calendar_get_setSkippedWallTimeOption_basic.phpt @@ -0,0 +1,67 @@ +--TEST-- +IntlCalendar::get/setSkippedWallTimeOption(): basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +if (version_compare(INTL_ICU_VERSION, '49') < 0) + die('skip for ICU 49+'); +--FILE-- + +<?php +ini_set("intl.error_level", E_WARNING); +ini_set("intl.default_locale", "nl"); + +date_default_timezone_set('Europe/Amsterdam'); + +//25 March 2012, transition to DST +$intlcal = new IntlGregorianCalendar(2012, 2, 25, 0, 0, 0); +var_dump($intlcal->getSkippedWallTimeOption()); +$intlcal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 2); +$intlcal->set(IntlCalendar::FIELD_MINUTE, 30); +echo "Should be 3h30\n"; +var_dump( + $intlcal->get(IntlCalendar::FIELD_HOUR_OF_DAY), + $intlcal->get(IntlCalendar::FIELD_MINUTE) +); + +var_dump($intlcal->setSkippedWallTimeOption(IntlCalendar::WALLTIME_FIRST)); +var_dump(intlcal_get_skipped_wall_time_option($intlcal)); +$intlcal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 2); +$intlcal->set(IntlCalendar::FIELD_MINUTE, 30); +echo "Should be 1h30\n"; +var_dump( + $intlcal->get(IntlCalendar::FIELD_HOUR_OF_DAY), + $intlcal->get(IntlCalendar::FIELD_MINUTE) +); + +var_dump(intlcal_set_skipped_wall_time_option($intlcal, IntlCalendar::WALLTIME_NEXT_VALID)); +var_dump($intlcal->getSkippedWallTimeOption()); +$intlcal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 2); +$intlcal->set(IntlCalendar::FIELD_MINUTE, 30); +echo "Should be 3h00\n"; +var_dump( + $intlcal->get(IntlCalendar::FIELD_HOUR_OF_DAY), + $intlcal->get(IntlCalendar::FIELD_MINUTE) +); + + +?> +==DONE== +--EXPECT-- + +int(0) +Should be 3h30 +int(3) +int(30) +bool(true) +int(1) +Should be 1h30 +int(1) +int(30) +bool(true) +int(2) +Should be 3h00 +int(3) +int(0) +==DONE== \ No newline at end of file diff --git a/ext/intl/tests/calendar_setSkipped_RepeatedWallTimeOption_error.phpt b/ext/intl/tests/calendar_setSkipped_RepeatedWallTimeOption_error.phpt new file mode 100644 index 0000000..0012fa1 --- /dev/null +++ b/ext/intl/tests/calendar_setSkipped_RepeatedWallTimeOption_error.phpt @@ -0,0 +1,80 @@ +--TEST-- +IntlCalendar::setSkipped/RepeatedWallTimeOption(): bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +if (version_compare(INTL_ICU_VERSION, '49') < 0) + die('skip for ICU 49+'); +--FILE-- +<?php +ini_set("intl.error_level", E_WARNING); + +$c = new IntlGregorianCalendar(NULL, 'pt_PT'); + +var_dump($c->setSkippedWallTimeOption()); +var_dump($c->setRepeatedWallTimeOption()); + +var_dump($c->setSkippedWallTimeOption(1, 2)); +var_dump($c->setRepeatedWallTimeOption(1, 2)); + +var_dump($c->setSkippedWallTimeOption(array())); +var_dump($c->setRepeatedWallTimeOption(array())); + +var_dump($c->setSkippedWallTimeOption(3)); +var_dump($c->setRepeatedWallTimeOption(2)); + +var_dump(intlcal_set_skipped_wall_time_option($c)); +var_dump(intlcal_set_repeated_wall_time_option($c)); + +var_dump(intlcal_set_repeated_wall_time_option(1, 1)); + +--EXPECTF-- + +Warning: IntlCalendar::setSkippedWallTimeOption() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::setSkippedWallTimeOption(): intlcal_set_skipped_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setRepeatedWallTimeOption() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: IntlCalendar::setRepeatedWallTimeOption(): intlcal_set_repeated_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setSkippedWallTimeOption() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::setSkippedWallTimeOption(): intlcal_set_skipped_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setRepeatedWallTimeOption() expects exactly 1 parameter, 2 given in %s on line %d + +Warning: IntlCalendar::setRepeatedWallTimeOption(): intlcal_set_repeated_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setSkippedWallTimeOption() expects parameter 1 to be long, array given in %s on line %d + +Warning: IntlCalendar::setSkippedWallTimeOption(): intlcal_set_skipped_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setRepeatedWallTimeOption() expects parameter 1 to be long, array given in %s on line %d + +Warning: IntlCalendar::setRepeatedWallTimeOption(): intlcal_set_repeated_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: IntlCalendar::setSkippedWallTimeOption(): intlcal_set_skipped_wall_time_option: invalid option in %s on line %d +bool(false) + +Warning: IntlCalendar::setRepeatedWallTimeOption(): intlcal_set_repeated_wall_time_option: invalid option in %s on line %d +bool(false) + +Warning: intlcal_set_skipped_wall_time_option() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: intlcal_set_skipped_wall_time_option(): intlcal_set_skipped_wall_time_option: bad arguments in %s on line %d +bool(false) + +Warning: intlcal_set_repeated_wall_time_option() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: intlcal_set_repeated_wall_time_option(): intlcal_set_repeated_wall_time_option: bad arguments in %s on line %d +bool(false) + +Catchable fatal error: Argument 1 passed to intlcal_set_repeated_wall_time_option() must be an instance of IntlCalendar, integer given in %s on line %d
« previous php.cvs (#68627) next »