31
31
* if set to 1 - store any error encountered in the parameter parse_error
32
32
* if set to 0 - no need to store any error encountered in the parameter parse_error
33
33
*/
34
- static void internal_parse_to_timestamp (IntlDateFormatter_object * dfo , char * text_to_parse , size_t text_len , int32_t * parse_pos , zval * return_value )
34
+ static void internal_parse_to_timestamp (IntlDateFormatter_object * dfo , char * text_to_parse , size_t text_len , int32_t * parse_pos , bool update_calendar , zval * return_value )
35
35
{
36
36
double result = 0 ;
37
37
UDate timestamp = 0 ;
@@ -42,13 +42,22 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex
42
42
intl_convert_utf8_to_utf16 (& text_utf16 , & text_utf16_len , text_to_parse , text_len , & INTL_DATA_ERROR_CODE (dfo ));
43
43
INTL_METHOD_CHECK_STATUS (dfo , "Error converting timezone to UTF-16" );
44
44
45
- timestamp = udat_parse ( DATE_FORMAT_OBJECT (dfo ), text_utf16 , text_utf16_len , parse_pos , & INTL_DATA_ERROR_CODE (dfo ));
46
- if ( text_utf16 ){
47
- efree (text_utf16 );
45
+ if (UNEXPECTED (update_calendar )) {
46
+ UCalendar * parsed_calendar = (UCalendar * )udat_getCalendar (DATE_FORMAT_OBJECT (dfo ));
47
+ udat_parseCalendar ( DATE_FORMAT_OBJECT (dfo ), parsed_calendar , text_utf16 , text_utf16_len , parse_pos , & INTL_DATA_ERROR_CODE (dfo ));
48
+ if ( text_utf16 ){
49
+ efree (text_utf16 );
50
+ }
51
+ INTL_METHOD_CHECK_STATUS ( dfo , "Calendar parsing failed" );
52
+ timestamp = ucal_getMillis ( parsed_calendar , & INTL_DATA_ERROR_CODE (dfo ));
53
+ } else {
54
+ timestamp = udat_parse ( DATE_FORMAT_OBJECT (dfo ), text_utf16 , text_utf16_len , parse_pos , & INTL_DATA_ERROR_CODE (dfo ));
55
+ if ( text_utf16 ){
56
+ efree (text_utf16 );
57
+ }
48
58
}
49
59
50
60
INTL_METHOD_CHECK_STATUS ( dfo , "Date parsing failed" );
51
-
52
61
/* Since return is in sec. */
53
62
result = (double )timestamp / U_MILLIS_PER_SECOND ;
54
63
if (result > (double )LONG_MAX || result < (double )LONG_MIN ) {
@@ -122,13 +131,14 @@ PHP_FUNCTION(datefmt_parse)
122
131
char * text_to_parse = NULL ;
123
132
size_t text_len = 0 ;
124
133
zval * z_parse_pos = NULL ;
125
- int32_t parse_pos = -1 ;
134
+ int32_t parse_pos = -1 ;
135
+ bool update_calendar = false;
126
136
127
137
DATE_FORMAT_METHOD_INIT_VARS ;
128
138
129
139
/* Parse parameters. */
130
- if ( zend_parse_method_parameters ( ZEND_NUM_ARGS (), getThis (), "Os|z!" ,
131
- & object , IntlDateFormatter_ce_ptr , & text_to_parse , & text_len , & z_parse_pos ) == FAILURE ){
140
+ if ( zend_parse_method_parameters ( ZEND_NUM_ARGS (), getThis (), "Os|z!b " ,
141
+ & object , IntlDateFormatter_ce_ptr , & text_to_parse , & text_len , & z_parse_pos , & update_calendar ) == FAILURE ){
132
142
RETURN_THROWS ();
133
143
}
134
144
@@ -149,7 +159,7 @@ PHP_FUNCTION(datefmt_parse)
149
159
RETURN_FALSE ;
150
160
}
151
161
}
152
- internal_parse_to_timestamp ( dfo , text_to_parse , text_len , z_parse_pos ?& parse_pos :NULL , return_value );
162
+ internal_parse_to_timestamp ( dfo , text_to_parse , text_len , z_parse_pos ?& parse_pos :NULL , update_calendar , return_value );
153
163
if (z_parse_pos ) {
154
164
zval_ptr_dtor (z_parse_pos );
155
165
ZVAL_LONG (z_parse_pos , parse_pos );
0 commit comments