diff options
Diffstat (limited to 'ext/intl/dateformat')
-rwxr-xr-x | ext/intl/dateformat/dateformat.c | 10 | ||||
-rwxr-xr-x | ext/intl/dateformat/dateformat_attr.c | 47 | ||||
-rwxr-xr-x | ext/intl/dateformat/dateformat_class.c | 9 | ||||
-rwxr-xr-x | ext/intl/dateformat/dateformat_format.c | 71 | ||||
-rwxr-xr-x | ext/intl/dateformat/dateformat_parse.c | 59 |
5 files changed, 105 insertions, 91 deletions
diff --git a/ext/intl/dateformat/dateformat.c b/ext/intl/dateformat/dateformat.c index 0eac9e9c7b..20e9d70887 100755 --- a/ext/intl/dateformat/dateformat.c +++ b/ext/intl/dateformat/dateformat.c @@ -75,7 +75,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) zval* object; long date_type = 0; long time_type = 0; - long calendar = UCAL_GREGORIAN; + long calendar = 1; char* timezone_str = NULL; int timezone_str_len = 0; char* pattern_str = NULL; @@ -91,7 +91,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) object = return_value; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sll|sls", - &locale, &locale_len, &date_type, &time_type, &timezone_str, &timezone_str_len, &calendar,&pattern_str, &pattern_str_len ) == FAILURE ) + &locale, &locale_len, &date_type, & time_type , &timezone_str, &timezone_str_len , &calendar ,&pattern_str , &pattern_str_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: unable to parse input parameters", 0 TSRMLS_CC ); zval_dtor(return_value); @@ -117,14 +117,14 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) } if( pattern_str && pattern_str_len>0 ){ - DATE_FORMAT_OBJECT(dfo) = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, timezone_utf16, timezone_utf16_len, svalue, slength, &INTL_DATA_ERROR_CODE(dfo)); + DATE_FORMAT_OBJECT(dfo) = udat_open(UDAT_IGNORE,UDAT_IGNORE, locale, timezone_utf16, timezone_utf16_len ,svalue ,slength , &INTL_DATA_ERROR_CODE(dfo)); } else { - DATE_FORMAT_OBJECT(dfo) = udat_open(time_type, date_type, locale, timezone_utf16, timezone_utf16_len, svalue, slength, &INTL_DATA_ERROR_CODE(dfo)); + DATE_FORMAT_OBJECT(dfo) = udat_open(time_type,date_type, locale, timezone_utf16, timezone_utf16_len ,svalue ,slength , &INTL_DATA_ERROR_CODE(dfo)); } /* Set the calendar if passed */ if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo)) && calendar) { - ucal_obj = ucal_open( timezone_utf16, timezone_utf16_len, locale, calendar, &INTL_DATA_ERROR_CODE(dfo) ); + ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(dfo) ); if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { udat_setCalendar( DATE_FORMAT_OBJECT(dfo), ucal_obj ); } diff --git a/ext/intl/dateformat/dateformat_attr.c b/ext/intl/dateformat/dateformat_attr.c index 51012896ed..717b44b1d6 100755 --- a/ext/intl/dateformat/dateformat_attr.c +++ b/ext/intl/dateformat/dateformat_attr.c @@ -26,10 +26,11 @@ #include <unicode/udat.h> #include <unicode/ucal.h> -static void internal_set_calendar(IntlDateFormatter_object *dfo, char* timezone_id, int timezone_id_len, int calendar, zval* return_value TSRMLS_DC){ +static void internal_set_calendar(IntlDateFormatter_object *dfo, char* timezone_id , int timezone_id_len , int calendar ,zval* return_value TSRMLS_DC){ int timezone_utf16_len = 0; UChar* timezone_utf16 = NULL; /* timezone_id in UTF-16 */ char* locale = NULL; + int locale_type =ULOC_ACTUAL_LOCALE; UCalendar* ucal_obj = NULL; @@ -42,14 +43,14 @@ static void internal_set_calendar(IntlDateFormatter_object *dfo, char* timezone_ } /* Convert timezone to UTF-16. */ - intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_id, timezone_id_len, &INTL_DATA_ERROR_CODE(dfo)); + intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_id, timezone_id_len , &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); - /* Get the locale for the dateformatter */ - locale = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(dfo)); + /* Get the lcoale for the dateformatter */ + locale = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), locale_type ,&INTL_DATA_ERROR_CODE(dfo)); /* Set the calendar if passed */ - ucal_obj = ucal_open(timezone_utf16, timezone_utf16_len, locale, calendar, &INTL_DATA_ERROR_CODE(dfo) ); + ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(dfo) ); udat_setCalendar( DATE_FORMAT_OBJECT(dfo), ucal_obj ); INTL_METHOD_CHECK_STATUS(dfo, "Error setting the calendar."); @@ -70,7 +71,7 @@ PHP_FUNCTION( datefmt_get_datetype ) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set( NULL , U_ILLEGAL_ARGUMENT_ERROR, "datefmt_get_datetype: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; } @@ -96,7 +97,7 @@ PHP_FUNCTION( datefmt_get_timetype ) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set( NULL , U_ILLEGAL_ARGUMENT_ERROR, "datefmt_get_timetype: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; } @@ -123,7 +124,7 @@ PHP_FUNCTION( datefmt_get_calendar ) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set( NULL , U_ILLEGAL_ARGUMENT_ERROR, "datefmt_get_calendar: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; } @@ -133,7 +134,7 @@ PHP_FUNCTION( datefmt_get_calendar ) INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter calendar." ); - RETURN_LONG(dfo->calendar); + RETURN_LONG(dfo->calendar ); } /* }}} */ @@ -149,7 +150,7 @@ PHP_FUNCTION( datefmt_get_timezone_id ) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set( NULL , U_ILLEGAL_ARGUMENT_ERROR, "datefmt_get_timezone_id: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; } @@ -160,7 +161,7 @@ PHP_FUNCTION( datefmt_get_timezone_id ) INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter timezone_id." ); if( dfo->timezone_id ){ - RETURN_STRING((char*)dfo->timezone_id, TRUE ); + RETURN_STRING((char*)dfo->timezone_id ,TRUE ); }else{ RETURN_NULL(); } @@ -168,7 +169,7 @@ PHP_FUNCTION( datefmt_get_timezone_id ) /* {{{ proto boolean IntlDateFormatter::setTimeZoneId( $timezone_id) * Set formatter timezone_id. }}} */ -/* {{{ proto boolean datefmt_set_timezone_id( IntlDateFormatter $mf,$timezone_id) +/* {{{ proto boolean datefmt_set_timezone_id( IntlDateFormatter $mf ,$timezone_id) * Set formatter timezone_id. */ PHP_FUNCTION( datefmt_set_timezone_id ) @@ -179,7 +180,7 @@ PHP_FUNCTION( datefmt_set_timezone_id ) DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, IntlDateFormatter_ce_ptr,&timezone_id, &timezone_id_len) == FAILURE ) + if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, IntlDateFormatter_ce_ptr ,&timezone_id , &timezone_id_len) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_set_timezone_id: unable to parse input params", 0 TSRMLS_CC ); @@ -190,13 +191,13 @@ PHP_FUNCTION( datefmt_set_timezone_id ) DATE_FORMAT_METHOD_FETCH_OBJECT; /* set the timezone for the calendar */ - internal_set_calendar( dfo, timezone_id, timezone_id_len, dfo->calendar, return_value TSRMLS_CC ); + internal_set_calendar( dfo , timezone_id , timezone_id_len , dfo->calendar ,return_value TSRMLS_CC ); /* Set the IntlDateFormatter variable */ if( dfo->timezone_id ){ efree(dfo->timezone_id); } - dfo->timezone_id = estrndup(timezone_id, timezone_id_len); + dfo->timezone_id = estrndup(timezone_id , timezone_id_len); RETURN_TRUE; } @@ -231,7 +232,7 @@ PHP_FUNCTION( datefmt_get_pattern ) ++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */ INTL_DATA_ERROR_CODE(dfo) = U_ZERO_ERROR; value = eumalloc(length); - length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized, value, length, &INTL_DATA_ERROR_CODE(dfo) ); + length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized , value, length, &INTL_DATA_ERROR_CODE(dfo) ); if(U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { efree(value); value = value_buf; @@ -274,7 +275,7 @@ PHP_FUNCTION( datefmt_set_pattern ) intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error converting pattern to UTF-16" ); - udat_applyPattern(DATE_FORMAT_OBJECT(dfo), (UBool)is_pattern_localized, svalue, slength); + udat_applyPattern(DATE_FORMAT_OBJECT(dfo), (UBool)is_pattern_localized , svalue, slength); efree(svalue); INTL_METHOD_CHECK_STATUS(dfo, "Error setting symbol value"); @@ -297,7 +298,7 @@ PHP_FUNCTION( datefmt_get_locale ) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", - &object, IntlDateFormatter_ce_ptr,&loc_type) == FAILURE ) + &object, IntlDateFormatter_ce_ptr ,&loc_type) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_get_locale: unable to parse input params", 0 TSRMLS_CC ); @@ -308,7 +309,7 @@ PHP_FUNCTION( datefmt_get_locale ) /* Fetch the object. */ DATE_FORMAT_METHOD_FETCH_OBJECT; - loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type,&INTL_DATA_ERROR_CODE(dfo)); + loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type ,&INTL_DATA_ERROR_CODE(dfo)); RETURN_STRING(loc, 1); } /* }}} */ @@ -353,7 +354,7 @@ PHP_FUNCTION( datefmt_set_lenient ) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ob", - &object, IntlDateFormatter_ce_ptr,&isLenient ) == FAILURE ) + &object, IntlDateFormatter_ce_ptr ,&isLenient ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_set_lenient: unable to parse input params", 0 TSRMLS_CC ); @@ -363,7 +364,7 @@ PHP_FUNCTION( datefmt_set_lenient ) /* Fetch the object. */ DATE_FORMAT_METHOD_FETCH_OBJECT; - udat_setLenient(DATE_FORMAT_OBJECT(dfo), (UBool)isLenient ); + udat_setLenient(DATE_FORMAT_OBJECT(dfo) , (UBool)isLenient ); } /* }}} */ @@ -396,10 +397,10 @@ PHP_FUNCTION( datefmt_set_calendar ) DATE_FORMAT_METHOD_FETCH_OBJECT; - internal_set_calendar( dfo, dfo->timezone_id, strlen(dfo->timezone_id), calendar, return_value TSRMLS_CC ); + internal_set_calendar( dfo , dfo->timezone_id , strlen(dfo->timezone_id) , calendar ,return_value TSRMLS_CC ); /* Set the calendar value in the IntlDateFormatter object */ - dfo->calendar = calendar; + dfo->calendar = calendar ; RETURN_TRUE; } diff --git a/ext/intl/dateformat/dateformat_class.c b/ext/intl/dateformat/dateformat_class.c index 7df95816e2..7ee38c47fe 100755 --- a/ext/intl/dateformat/dateformat_class.c +++ b/ext/intl/dateformat/dateformat_class.c @@ -84,35 +84,42 @@ zend_object_value IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC */ /* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(datefmt_parse_args, 0, 0, 1) +static ZEND_BEGIN_ARG_INFO_EX(datefmt_parse_args, 0, 0, 1) ZEND_ARG_INFO(0, string) ZEND_ARG_INFO(1, position) ZEND_END_ARG_INFO() +static ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_format, 0, 0, 0) ZEND_ARG_INFO(0, args) ZEND_ARG_INFO(0, array) ZEND_END_ARG_INFO() +static ZEND_BEGIN_ARG_INFO(arginfo_intldateformatter_getdatetype, 0) ZEND_END_ARG_INFO() +static ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_settimezoneid, 0, 0, 1) ZEND_ARG_INFO(0, zone) ZEND_END_ARG_INFO() +static ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setpattern, 0, 0, 1) ZEND_ARG_INFO(0, pattern) ZEND_END_ARG_INFO() +static ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setlenient, 0, 0, 1) ZEND_ARG_INFO(0, lenient) ZEND_END_ARG_INFO() +static ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setcalendar, 0, 0, 1) ZEND_ARG_INFO(0, which) ZEND_END_ARG_INFO() +static ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter___construct, 0, 0, 3) ZEND_ARG_INFO(0, locale) ZEND_ARG_INFO(0, datetype) diff --git a/ext/intl/dateformat/dateformat_format.c b/ext/intl/dateformat/dateformat_format.c index e41b38beb1..f56a397ea0 100755 --- a/ext/intl/dateformat/dateformat_format.c +++ b/ext/intl/dateformat/dateformat_format.c @@ -31,8 +31,7 @@ /* {{{ * Internal function which calls the udat_format */ -static void internal_format(IntlDateFormatter_object *dfo, UDate timestamp, zval *return_value TSRMLS_DC) -{ +static void internal_format(IntlDateFormatter_object *dfo, UDate timestamp , zval *return_value TSRMLS_DC){ UChar* formatted = NULL; int32_t resultlengthneeded =0 ; @@ -58,12 +57,11 @@ static void internal_format(IntlDateFormatter_object *dfo, UDate timestamp, zval /* {{{ * Internal function which fetches an element from the passed array for the key_name passed */ -static double internal_get_arr_ele(IntlDateFormatter_object *dfo, HashTable* hash_arr, char* key_name TSRMLS_DC) -{ +static double internal_get_arr_ele(IntlDateFormatter_object *dfo , HashTable* hash_arr ,char* key_name TSRMLS_DC){ zval** ele_value = NULL; UDate result = -1; - if( zend_hash_find( hash_arr, key_name, strlen(key_name) + 1, (void **)&ele_value ) == SUCCESS ){ + if( zend_hash_find( hash_arr , key_name , strlen(key_name) + 1 ,(void **)&ele_value ) == SUCCESS ){ if( Z_TYPE_PP(ele_value)!= IS_LONG ){ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: parameter array does not contain a long element.", 0 TSRMLS_CC ); @@ -71,16 +69,15 @@ static double internal_get_arr_ele(IntlDateFormatter_object *dfo, HashTable* has result = Z_LVAL_PP(ele_value); } } - /* printf("\n Inside internal_get_arr_ele key_name= %s, result = %g \n", key_name, result); */ + /* printf("\n Inside internal_get_arr_ele key_name= %s , result = %g \n" , key_name, result); */ return result; } /* }}} */ /* {{{ - * Internal function which sets UCalendar from the passed array and retrieves timestamp + * Internal function which creates a UCalendar from the passed array */ -static UDate internal_get_timestamp(IntlDateFormatter_object *dfo, HashTable* hash_arr TSRMLS_DC) -{ +static void internal_create_ucal(IntlDateFormatter_object *dfo, HashTable* hash_arr , UCalendar* pcal TSRMLS_DC){ long year =0; long month =0; long hour =0; @@ -90,30 +87,31 @@ static UDate internal_get_timestamp(IntlDateFormatter_object *dfo, HashTable* ha long yday =0; long mday =0; UBool isInDST = FALSE; - UCalendar *pcal; /* Fetch values from the incoming array */ - year = internal_get_arr_ele( dfo, hash_arr, CALENDAR_YEAR TSRMLS_CC) + 1900; /* tm_year is years since 1900 */ + year = internal_get_arr_ele( dfo , hash_arr , CALENDAR_YEAR TSRMLS_CC) + 1900; /* tm_year is years since 1900 */ /* Month in ICU and PHP starts from January =0 */ - month = internal_get_arr_ele( dfo, hash_arr, CALENDAR_MON TSRMLS_CC); - hour = internal_get_arr_ele( dfo, hash_arr, CALENDAR_HOUR TSRMLS_CC); - minute = internal_get_arr_ele( dfo, hash_arr, CALENDAR_MIN TSRMLS_CC); - second = internal_get_arr_ele( dfo, hash_arr, CALENDAR_SEC TSRMLS_CC); - wday = internal_get_arr_ele( dfo, hash_arr, CALENDAR_WDAY TSRMLS_CC); - yday = internal_get_arr_ele( dfo, hash_arr, CALENDAR_YDAY TSRMLS_CC); - isInDST = internal_get_arr_ele( dfo, hash_arr, CALENDAR_ISDST TSRMLS_CC); - /* For the ucal_setDateTime() function, this is the 'date' value */ - mday = internal_get_arr_ele( dfo, hash_arr, CALENDAR_MDAY TSRMLS_CC); - - pcal = udat_getCalendar(DATE_FORMAT_OBJECT(dfo)); + month = internal_get_arr_ele( dfo , hash_arr , CALENDAR_MON TSRMLS_CC); + hour = internal_get_arr_ele( dfo , hash_arr , CALENDAR_HOUR TSRMLS_CC); + minute = internal_get_arr_ele( dfo , hash_arr , CALENDAR_MIN TSRMLS_CC); + second = internal_get_arr_ele( dfo , hash_arr , CALENDAR_SEC TSRMLS_CC); + wday = internal_get_arr_ele( dfo , hash_arr , CALENDAR_WDAY TSRMLS_CC); + yday = internal_get_arr_ele( dfo , hash_arr , CALENDAR_YDAY TSRMLS_CC); + isInDST = internal_get_arr_ele( dfo , hash_arr , CALENDAR_ISDST TSRMLS_CC); + /* For the ucal_setDateTime() function , this is the 'date' value */ + mday = internal_get_arr_ele( dfo , hash_arr , CALENDAR_MDAY TSRMLS_CC); + /* set the incoming values for the calendar */ - ucal_setDateTime( pcal, year, month, mday, hour, minute, second, &INTL_DATA_ERROR_CODE(dfo)); + ucal_setDateTime( pcal, year, month , mday , hour , minute , second , &INTL_DATA_ERROR_CODE(dfo)); if( INTL_DATA_ERROR_CODE(dfo) != U_ZERO_ERROR){ - return 0; + return; } + /* ICU UCAL_DAY_OF_WEEK starts from SUNDAY=1 thru SATURDAY=7 + * whereas PHP localtime has tm_wday SUNDAY=0 thru SATURDAY=6 */ + ucal_set( pcal, UCAL_DAY_OF_WEEK , (wday+1)); + ucal_set( pcal, UCAL_DAY_OF_YEAR , yday); - /* Fetch the timestamp from the UCalendar */ - return ucal_getMillis(pcal, &INTL_DATA_ERROR_CODE(dfo) ); + /* TO DO: How to set the isInDST field?Is it required to set */ } @@ -125,13 +123,14 @@ PHP_FUNCTION(datefmt_format) { UDate timestamp =0; UDate p_timestamp =0; + UCalendar* temp_cal ; HashTable* hash_arr = NULL; zval* zarg = NULL; DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz", &object, IntlDateFormatter_ce_ptr,&zarg ) == FAILURE ) + if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz", &object, IntlDateFormatter_ce_ptr ,&zarg ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; @@ -154,17 +153,27 @@ PHP_FUNCTION(datefmt_format) hash_arr = Z_ARRVAL_P(zarg); if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 ) RETURN_FALSE; - - timestamp = internal_get_timestamp(dfo, hash_arr TSRMLS_CC); + /* Create a UCalendar object from the array and then format it */ + temp_cal = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &INTL_DATA_ERROR_CODE(dfo)); + ucal_clear(temp_cal); + INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed while creating calendar from the array" ) + internal_create_ucal( dfo , hash_arr , temp_cal TSRMLS_CC); + INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed while creating calendar from the array" ) + /* Fetch the timestamp from the created UCalendar */ + timestamp = ucal_getMillis(temp_cal , &INTL_DATA_ERROR_CODE(dfo) ); INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed" ) break; +/* + case IS_OBJECT: + break; +*/ default: intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "datefmt_format: takes either an array or an integer timestamp value ", 0 TSRMLS_CC ); + "datefmt_format: takes either an array or an integer TimeStamp value ", 0 TSRMLS_CC ); RETURN_FALSE; } - internal_format( dfo, timestamp, return_value TSRMLS_CC); + internal_format( dfo, timestamp ,return_value TSRMLS_CC); } diff --git a/ext/intl/dateformat/dateformat_parse.c b/ext/intl/dateformat/dateformat_parse.c index c17089f1ca..3e05050760 100755 --- a/ext/intl/dateformat/dateformat_parse.c +++ b/ext/intl/dateformat/dateformat_parse.c @@ -33,18 +33,17 @@ * if set to 1 - store any error encountered in the parameter parse_error * if set to 0 - no need to store any error encountered in the parameter parse_error */ -static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* text_to_parse, int32_t text_len, int32_t *parse_pos, zval *return_value TSRMLS_DC) -{ +static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* text_to_parse , int32_t text_len, int32_t *parse_pos , zval *return_value TSRMLS_DC){ long result = 0; UDate timestamp =0; UChar* text_utf16 = NULL; int32_t text_utf16_len = 0; /* Convert timezone to UTF-16. */ - intl_convert_utf8_to_utf16(&text_utf16, &text_utf16_len, text_to_parse, text_len, &INTL_DATA_ERROR_CODE(dfo)); + intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); - timestamp = udat_parse( DATE_FORMAT_OBJECT(dfo), text_utf16, text_utf16_len, parse_pos, &INTL_DATA_ERROR_CODE(dfo)); + timestamp = udat_parse( DATE_FORMAT_OBJECT(dfo), text_utf16 , text_utf16_len , parse_pos , &INTL_DATA_ERROR_CODE(dfo)); if( text_utf16 ){ efree(text_utf16); } @@ -61,38 +60,36 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex } /* }}} */ -static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_value, UCalendar parsed_calendar, long calendar_field, char* key_name TSRMLS_DC) -{ - long calendar_field_val = ucal_get( parsed_calendar, calendar_field, &INTL_DATA_ERROR_CODE(dfo)); +static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_value ,UCalendar parsed_calendar , long calendar_field , char* key_name TSRMLS_DC){ + long calendar_field_val = ucal_get( parsed_calendar , calendar_field , &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : could not get a field from calendar" ); - if( strcmp(key_name, CALENDAR_YEAR )==0 ){ + if( strcmp(key_name , CALENDAR_YEAR )==0 ){ /* since tm_year is years from 1900 */ - add_assoc_long( return_value, key_name,( calendar_field_val-1900) ); - }else if( strcmp(key_name, CALENDAR_WDAY )==0 ){ + add_assoc_long( return_value, key_name ,( calendar_field_val-1900) ); + }else if( strcmp(key_name , CALENDAR_WDAY )==0 ){ /* since tm_wday starts from 0 whereas ICU WDAY start from 1 */ - add_assoc_long( return_value, key_name,( calendar_field_val-1) ); + add_assoc_long( return_value, key_name ,( calendar_field_val-1) ); }else{ - add_assoc_long( return_value, key_name, calendar_field_val ); + add_assoc_long( return_value, key_name , calendar_field_val ); } } /* {{{ * Internal function which calls the udat_parseCalendar */ -static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* text_to_parse, int32_t text_len, int32_t *parse_pos, zval *return_value TSRMLS_DC) -{ +static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* text_to_parse , int32_t text_len, int32_t *parse_pos , zval *return_value TSRMLS_DC){ UCalendar* parsed_calendar = NULL; UChar* text_utf16 = NULL; int32_t text_utf16_len = 0; long isInDST = 0; /* Convert timezone to UTF-16. */ - intl_convert_utf8_to_utf16(&text_utf16, &text_utf16_len, text_to_parse, text_len, &INTL_DATA_ERROR_CODE(dfo)); + intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); - parsed_calendar = udat_getCalendar(DATE_FORMAT_OBJECT(dfo)); - udat_parseCalendar( DATE_FORMAT_OBJECT(dfo), parsed_calendar, text_utf16, text_utf16_len, parse_pos, &INTL_DATA_ERROR_CODE(dfo)); + parsed_calendar = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &INTL_DATA_ERROR_CODE(dfo)); + udat_parseCalendar( DATE_FORMAT_OBJECT(dfo), parsed_calendar , text_utf16 , text_utf16_len , parse_pos , &INTL_DATA_ERROR_CODE(dfo)); if (text_utf16) { efree(text_utf16); @@ -103,19 +100,19 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex array_init( return_value ); /* Add entries from various fields of the obtained parsed_calendar */ - add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_SECOND, CALENDAR_SEC TSRMLS_CC); - add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_MINUTE, CALENDAR_MIN TSRMLS_CC); - add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_HOUR_OF_DAY, CALENDAR_HOUR TSRMLS_CC); - add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_YEAR, CALENDAR_YEAR TSRMLS_CC); - add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_DAY_OF_MONTH, CALENDAR_MDAY TSRMLS_CC); - add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_DAY_OF_WEEK, CALENDAR_WDAY TSRMLS_CC); - add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_DAY_OF_YEAR, CALENDAR_YDAY TSRMLS_CC); - add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_MONTH, CALENDAR_MON TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_SECOND , CALENDAR_SEC TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_MINUTE , CALENDAR_MIN TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_HOUR_OF_DAY , CALENDAR_HOUR TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_YEAR , CALENDAR_YEAR TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_DAY_OF_MONTH , CALENDAR_MDAY TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_DAY_OF_WEEK , CALENDAR_WDAY TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_DAY_OF_YEAR , CALENDAR_YDAY TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_MONTH , CALENDAR_MON TSRMLS_CC); /* Is in DST? */ - isInDST = ucal_inDaylightTime(parsed_calendar , &INTL_DATA_ERROR_CODE(dfo)); + isInDST = ucal_inDaylightTime(parsed_calendar , &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : while checking if currently in DST." ); - add_assoc_long( return_value, CALENDAR_ISDST,(isInDST==1?1:0)); + add_assoc_long( return_value, CALENDAR_ISDST ,(isInDST==1?1:0)); } /* }}} */ @@ -135,7 +132,7 @@ PHP_FUNCTION(datefmt_parse) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|z!", - &object, IntlDateFormatter_ce_ptr, &text_to_parse, &text_len, &z_parse_pos ) == FAILURE ){ + &object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &z_parse_pos ) == FAILURE ){ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_parse: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; } @@ -150,7 +147,7 @@ PHP_FUNCTION(datefmt_parse) RETURN_FALSE; } } - internal_parse_to_timestamp( dfo, text_to_parse, text_len, z_parse_pos?&parse_pos:NULL, return_value TSRMLS_CC); + internal_parse_to_timestamp( dfo, text_to_parse, text_len, z_parse_pos?&parse_pos:NULL, return_value TSRMLS_CC); if(z_parse_pos) { zval_dtor(z_parse_pos); ZVAL_LONG(z_parse_pos, parse_pos); @@ -173,7 +170,7 @@ PHP_FUNCTION(datefmt_localtime) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|z!", - &object, IntlDateFormatter_ce_ptr, &text_to_parse, &text_len, &z_parse_pos ) == FAILURE ){ + &object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &z_parse_pos ) == FAILURE ){ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_parse_to_localtime: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; } @@ -188,7 +185,7 @@ PHP_FUNCTION(datefmt_localtime) RETURN_FALSE; } } - internal_parse_to_localtime( dfo, text_to_parse, text_len, z_parse_pos?&parse_pos:NULL, return_value TSRMLS_CC); + internal_parse_to_localtime( dfo, text_to_parse , text_len , z_parse_pos?&parse_pos:NULL, return_value TSRMLS_CC); if(z_parse_pos) { zval_dtor(z_parse_pos); ZVAL_LONG(z_parse_pos, parse_pos); |