mirror of
https://github.com/php/php-src.git
synced 2024-11-24 18:34:21 +08:00
intl: add intlcal_set_minimal_days_in_first_week()
and IntlCalendar::setMinimalDaysInFirstWeek(). This one had slipped. we had a ::getMinimalDaysInFirstWeek() but no way to change the value.
This commit is contained in:
parent
1aeb2514fe
commit
a4538a4ca2
@ -361,6 +361,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_set_minimal_days_in_first_week, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, numberOfDays)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_from_date_time, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, dateTime)
|
||||
ZEND_END_ARG_INFO()
|
||||
@ -433,6 +437,7 @@ static const zend_function_entry Calendar_class_functions[] = {
|
||||
#endif
|
||||
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(setMinimalDaysInFirstWeek,intlcal_set_minimal_days_in_first_week,ainfo_cal_set_minimal_days_in_first_week,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)
|
||||
|
@ -997,6 +997,32 @@ U_CFUNC PHP_FUNCTION(intlcal_set_lenient)
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
U_CFUNC PHP_FUNCTION(intlcal_set_minimal_days_in_first_week)
|
||||
{
|
||||
long num_days;
|
||||
CALENDAR_METHOD_INIT_VARS;
|
||||
|
||||
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
|
||||
"Ol", &object, Calendar_ce_ptr, &num_days) == FAILURE) {
|
||||
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
|
||||
"intlcal_set_minimal_days_in_first_week: bad arguments", 0 TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (num_days < 1 || num_days > 7) {
|
||||
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
|
||||
"intlcal_set_minimal_days_in_first_week: invalid number of days; "
|
||||
"must be between 1 and 7", 0 TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
CALENDAR_METHOD_FETCH_OBJECT;
|
||||
|
||||
co->ucal->setMinimalDaysInFirstWeek((uint8_t)num_days);
|
||||
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
U_CFUNC PHP_FUNCTION(intlcal_equals)
|
||||
{
|
||||
zval *other_object;
|
||||
|
@ -91,6 +91,8 @@ PHP_FUNCTION(intlcal_set_first_day_of_week);
|
||||
|
||||
PHP_FUNCTION(intlcal_set_lenient);
|
||||
|
||||
PHP_FUNCTION(intlcal_set_minimal_days_in_first_week);
|
||||
|
||||
PHP_FUNCTION(intlcal_equals);
|
||||
|
||||
PHP_FUNCTION(intlcal_get_repeated_wall_time_option);
|
||||
|
@ -590,6 +590,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_set_minimal_days_in_first_week, 0, 0, 2 )
|
||||
ZEND_ARG_OBJ_INFO( 0, calendar, IntlCalendar, 0 )
|
||||
ZEND_ARG_INFO( 0, numberOfDays )
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_from_date_time, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, dateTime)
|
||||
ZEND_END_ARG_INFO()
|
||||
@ -828,6 +833,7 @@ zend_function_entry intl_functions[] = {
|
||||
#endif
|
||||
PHP_FE( intlcal_set_first_day_of_week, ainfo_cal_dow )
|
||||
PHP_FE( intlcal_set_lenient, ainfo_cal_set_lenient )
|
||||
PHP_FE( intlcal_set_minimal_days_in_first_week, ainfo_cal_set_minimal_days_in_first_week )
|
||||
PHP_FE( intlcal_equals, ainfo_cal_other_cal )
|
||||
PHP_FE( intlcal_from_date_time, ainfo_cal_from_date_time )
|
||||
PHP_FE( intlcal_to_date_time, ainfo_cal_only_cal )
|
||||
|
26
ext/intl/tests/calendar_setMinimalDaysInFirstWeek_basic.phpt
Normal file
26
ext/intl/tests/calendar_setMinimalDaysInFirstWeek_basic.phpt
Normal file
@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
IntlCalendar::setMinimalDaysInFirstWeek() 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->setMinimalDaysInFirstWeek(6),
|
||||
$intlcal->getMinimalDaysInFirstWeek(),
|
||||
intlcal_set_minimal_days_in_first_week($intlcal, 5),
|
||||
$intlcal->getMinimalDaysInFirstWeek()
|
||||
);
|
||||
?>
|
||||
==DONE==
|
||||
--EXPECT--
|
||||
bool(true)
|
||||
int(6)
|
||||
bool(true)
|
||||
int(5)
|
||||
==DONE==
|
40
ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt
Normal file
40
ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt
Normal file
@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
IntlCalendar::setMinimalDaysInFirstWeek(): bad arguments
|
||||
--INI--
|
||||
date.timezone=Atlantic/Azores
|
||||
--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->setMinimalDaysInFirstWeek());
|
||||
var_dump($c->setMinimalDaysInFirstWeek(1, 2));
|
||||
var_dump($c->setMinimalDaysInFirstWeek(0));
|
||||
|
||||
var_dump(intlcal_set_minimal_days_in_first_week($c, 0));
|
||||
var_dump(intlcal_set_minimal_days_in_first_week(1, 2));
|
||||
|
||||
--EXPECTF--
|
||||
Warning: IntlCalendar::setMinimalDaysInFirstWeek() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
|
||||
Warning: IntlCalendar::setMinimalDaysInFirstWeek(): intlcal_set_minimal_days_in_first_week: bad arguments in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: IntlCalendar::setMinimalDaysInFirstWeek() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
|
||||
Warning: IntlCalendar::setMinimalDaysInFirstWeek(): intlcal_set_minimal_days_in_first_week: bad arguments in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: IntlCalendar::setMinimalDaysInFirstWeek(): intlcal_set_minimal_days_in_first_week: invalid number of days; must be between 1 and 7 in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: intlcal_set_minimal_days_in_first_week(): intlcal_set_minimal_days_in_first_week: invalid number of days; must be between 1 and 7 in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Catchable fatal error: Argument 1 passed to intlcal_set_minimal_days_in_first_week() must be an instance of IntlCalendar, integer given in %s on line %d
|
||||
|
Loading…
Reference in New Issue
Block a user