mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
fix formatting/parsing
This commit is contained in:
parent
95d9565902
commit
d8c0c2203b
2 changed files with 61 additions and 67 deletions
|
@ -31,7 +31,8 @@
|
|||
/* {{{
|
||||
* 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 ;
|
||||
|
||||
|
@ -57,7 +58,8 @@ static void internal_format(IntlDateFormatter_object *dfo, UDate timestamp , zva
|
|||
/* {{{
|
||||
* 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;
|
||||
|
||||
|
@ -75,9 +77,10 @@ static double internal_get_arr_ele(IntlDateFormatter_object *dfo , HashTable* h
|
|||
/* }}} */
|
||||
|
||||
/* {{{
|
||||
* Internal function which creates a UCalendar from the passed array
|
||||
* Internal function which sets UCalendar from the passed array and retrieves timestamp
|
||||
*/
|
||||
static void internal_create_ucal(IntlDateFormatter_object *dfo, HashTable* hash_arr , UCalendar* pcal TSRMLS_DC){
|
||||
static UDate internal_get_timestamp(IntlDateFormatter_object *dfo, HashTable* hash_arr TSRMLS_DC)
|
||||
{
|
||||
long year =0;
|
||||
long month =0;
|
||||
long hour =0;
|
||||
|
@ -87,6 +90,7 @@ static void internal_create_ucal(IntlDateFormatter_object *dfo, HashTable* hash_
|
|||
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 */
|
||||
|
@ -101,17 +105,15 @@ static void internal_create_ucal(IntlDateFormatter_object *dfo, HashTable* hash_
|
|||
/* 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));
|
||||
/* set the incoming values for the calendar */
|
||||
ucal_setDateTime( pcal, year, month, mday, hour, minute, second, &INTL_DATA_ERROR_CODE(dfo));
|
||||
if( INTL_DATA_ERROR_CODE(dfo) != U_ZERO_ERROR){
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
/* 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);
|
||||
|
||||
/* TO DO: How to set the isInDST field?Is it required to set */
|
||||
/* Fetch the timestamp from the UCalendar */
|
||||
return ucal_getMillis(pcal, &INTL_DATA_ERROR_CODE(dfo) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,7 +125,6 @@ PHP_FUNCTION(datefmt_format)
|
|||
{
|
||||
UDate timestamp =0;
|
||||
UDate p_timestamp =0;
|
||||
UCalendar* temp_cal ;
|
||||
HashTable* hash_arr = NULL;
|
||||
zval* zarg = NULL;
|
||||
|
||||
|
@ -153,23 +154,13 @@ PHP_FUNCTION(datefmt_format)
|
|||
hash_arr = Z_ARRVAL_P(zarg);
|
||||
if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 )
|
||||
RETURN_FALSE;
|
||||
/* 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) );
|
||||
|
||||
timestamp = internal_get_timestamp(dfo, hash_arr TSRMLS_CC);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
* 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;
|
||||
|
@ -60,7 +61,8 @@ 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){
|
||||
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" );
|
||||
|
||||
|
@ -78,7 +80,8 @@ static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_va
|
|||
/* {{{
|
||||
* 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;
|
||||
|
@ -88,7 +91,7 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex
|
|||
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 = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &INTL_DATA_ERROR_CODE(dfo));
|
||||
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));
|
||||
|
||||
if (text_utf16) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue