Commit:    a4538a4ca2db39706625bf29379360ea963c908a
Author:    Gustavo André dos Santos Lopes <cataphr...@php.net>         Wed, 3 
Jul 2013 04:57:23 +0100
Parents:   1aeb2514fe210c99c3e566d59788e76a8b3018d8
Branches:  PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=a4538a4ca2db39706625bf29379360ea963c908a

Log:
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.

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_setMinimalDaysInFirstWeek_basic.phpt
  A  ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt


Diff:
diff --git a/ext/intl/calendar/calendar_class.cpp 
b/ext/intl/calendar/calendar_class.cpp
index beb65f7..9495a00 100644
--- a/ext/intl/calendar/calendar_class.cpp
+++ b/ext/intl/calendar/calendar_class.cpp
@@ -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)
diff --git a/ext/intl/calendar/calendar_methods.cpp 
b/ext/intl/calendar/calendar_methods.cpp
index 2d33bd1..db10502 100644
--- a/ext/intl/calendar/calendar_methods.cpp
+++ b/ext/intl/calendar/calendar_methods.cpp
@@ -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;
diff --git a/ext/intl/calendar/calendar_methods.h 
b/ext/intl/calendar/calendar_methods.h
index 2be13e4..dfd0bbe 100644
--- a/ext/intl/calendar/calendar_methods.h
+++ b/ext/intl/calendar/calendar_methods.h
@@ -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);
diff --git a/ext/intl/php_intl.c b/ext/intl/php_intl.c
index a2c4d77..65e53c8 100644
--- a/ext/intl/php_intl.c
+++ b/ext/intl/php_intl.c
@@ -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
index 0000000..998e74b
--- /dev/null
+++ b/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_basic.phpt
@@ -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==
diff --git a/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt 
b/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt
new file mode 100644
index 0000000..c133558
--- /dev/null
+++ b/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt
@@ -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
+


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to