]> granicus.if.org Git - php/commitdiff
intl: add intlcal_set_minimal_days_in_first_week()
authorGustavo André dos Santos Lopes <cataphract@php.net>
Wed, 3 Jul 2013 03:57:23 +0000 (04:57 +0100)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Wed, 3 Jul 2013 04:06:32 +0000 (05:06 +0100)
and IntlCalendar::setMinimalDaysInFirstWeek(). This one had slipped.
we had a ::getMinimalDaysInFirstWeek() but no way to change the value.

ext/intl/calendar/calendar_class.cpp
ext/intl/calendar/calendar_methods.cpp
ext/intl/calendar/calendar_methods.h
ext/intl/php_intl.c
ext/intl/tests/calendar_setMinimalDaysInFirstWeek_basic.phpt [new file with mode: 0644]
ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt [new file with mode: 0644]

index beb65f718f43f6ce235b8e7023582a4a2a45f0fc..9495a00cc679a6a383abfbb58dce3e57a79e7483 100644 (file)
@@ -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)
index 2d33bd1952f2fd85600800fc29e06b3b36927be2..db10502a1837f17d94b5ae046a6f596995a961cf 100644 (file)
@@ -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;
index 2be13e4920224db0f40ffdaac370691055f7e399..dfd0bbeeaf67e28eb1b905f257bf5b40d87cf53f 100644 (file)
@@ -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);
index a2c4d77651d4bfa0d171997c38c897283fc10252..65e53c8b5e8248dc111d7934d5652c8f7573132f 100644 (file)
@@ -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 )
diff --git a/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_basic.phpt b/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_basic.phpt
new file mode 100644 (file)
index 0000000..998e74b
--- /dev/null
@@ -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==\r
diff --git a/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt b/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt
new file mode 100644 (file)
index 0000000..c133558
--- /dev/null
@@ -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
+