|
21 | 21 | #include <unicode/ustring.h> |
22 | 22 | #include <unicode/ucal.h> |
23 | 23 |
|
24 | | -#include "php_intl.h" |
25 | | -#include "intl_convert.h" |
| 24 | +#include "../php_intl.h" |
| 25 | +#include "../intl_convert.h" |
| 26 | +#include "../common/common_date.h" |
26 | 27 | #include "dateformat.h" |
27 | 28 | #include "dateformat_class.h" |
28 | 29 | #include "dateformat_format.h" |
29 | 30 | #include "dateformat_data.h" |
30 | | -/* avoid redefinition of int8_t, already defined in unicode/pwin32.h */ |
31 | | -#define _MSC_STDINT_H_ 1 |
32 | | -#include "ext/date/php_date.h" |
33 | 31 |
|
34 | 32 | /* {{{ |
35 | 33 | * Internal function which calls the udat_format |
@@ -126,70 +124,38 @@ static UDate internal_get_timestamp(IntlDateFormatter_object *dfo, HashTable* ha |
126 | 124 | * Format the time value as a string. }}}*/ |
127 | 125 | PHP_FUNCTION(datefmt_format) |
128 | 126 | { |
129 | | - UDate timestamp =0; |
130 | | - UDate p_timestamp =0; |
131 | | - HashTable* hash_arr = NULL; |
132 | | - zval* zarg = NULL; |
| 127 | + UDate timestamp = 0; |
| 128 | + HashTable *hash_arr = NULL; |
| 129 | + zval *zarg = NULL; |
133 | 130 |
|
134 | 131 | DATE_FORMAT_METHOD_INIT_VARS; |
135 | 132 |
|
136 | 133 | /* Parse parameters. */ |
137 | | - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz", &object, IntlDateFormatter_ce_ptr,&zarg ) == FAILURE ) |
138 | | - { |
139 | | - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: unable to parse input params", 0 TSRMLS_CC ); |
| 134 | + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz", |
| 135 | + &object, IntlDateFormatter_ce_ptr, &zarg) == FAILURE) { |
| 136 | + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: unable " |
| 137 | + "to parse input params", 0 TSRMLS_CC ); |
140 | 138 | RETURN_FALSE; |
141 | 139 | } |
142 | 140 |
|
143 | | - /* Fetch the object. */ |
144 | 141 | DATE_FORMAT_METHOD_FETCH_OBJECT; |
145 | 142 |
|
146 | | - switch(Z_TYPE_P(zarg) ){ |
147 | | - case IS_LONG: |
148 | | - p_timestamp = Z_LVAL_P(zarg) ; |
149 | | - timestamp = p_timestamp * 1000; |
150 | | - break; |
151 | | - case IS_DOUBLE: |
152 | | - /* timestamp*1000 since ICU expects it in milliseconds */ |
153 | | - p_timestamp = Z_DVAL_P(zarg) ; |
154 | | - timestamp = p_timestamp * 1000; |
155 | | - break; |
156 | | - case IS_ARRAY: |
157 | | - hash_arr = Z_ARRVAL_P(zarg); |
158 | | - if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 ) |
159 | | - RETURN_FALSE; |
160 | | - |
161 | | - timestamp = internal_get_timestamp(dfo, hash_arr TSRMLS_CC); |
162 | | - INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed" ) |
163 | | - break; |
164 | | - case IS_OBJECT: { |
165 | | - zend_class_entry *date_ce = php_date_get_date_ce(); |
166 | | - zval retval; |
167 | | - zval *zfuncname; |
168 | | - if(!instanceof_function(Z_OBJCE_P(zarg), date_ce TSRMLS_CC)) { |
169 | | - intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: object must be an instance of DateTime", 0 TSRMLS_CC ); |
170 | | - RETURN_FALSE; |
171 | | - } |
172 | | - INIT_ZVAL(retval); |
173 | | - MAKE_STD_ZVAL(zfuncname); |
174 | | - ZVAL_STRING(zfuncname, "getTimestamp", 1); |
175 | | - if(call_user_function(NULL, &zarg, zfuncname, &retval, 0, NULL TSRMLS_CC) != SUCCESS || Z_TYPE(retval) != IS_LONG) { |
176 | | - intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: cannot get timestamp", 0 TSRMLS_CC ); |
177 | | - zval_ptr_dtor(&zfuncname); |
178 | | - RETURN_FALSE; |
179 | | - } |
180 | | - zval_ptr_dtor(&zfuncname); |
181 | | - p_timestamp = Z_LVAL(retval); |
182 | | - timestamp = p_timestamp*1000; |
183 | | - } |
184 | | - break; |
185 | | - default: |
186 | | - intl_errors_set( INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, |
187 | | - "datefmt_format: takes either an array or an integer timestamp value or a DateTime object", 0 TSRMLS_CC ); |
| 143 | + if (Z_TYPE_P(zarg) == IS_ARRAY) { |
| 144 | + hash_arr = Z_ARRVAL_P(zarg); |
| 145 | + if (!hash_arr || zend_hash_num_elements(hash_arr) == 0) { |
188 | 146 | RETURN_FALSE; |
189 | | - } |
| 147 | + } |
190 | 148 |
|
191 | | - internal_format( dfo, timestamp, return_value TSRMLS_CC); |
| 149 | + timestamp = internal_get_timestamp(dfo, hash_arr TSRMLS_CC); |
| 150 | + INTL_METHOD_CHECK_STATUS(dfo, "datefmt_format: date formatting failed") |
| 151 | + } else { |
| 152 | + timestamp = intl_zval_to_millis(zarg, |
| 153 | + &INTL_DATA_ERROR_CODE(dfo) TSRMLS_CC); |
| 154 | + INTL_METHOD_CHECK_STATUS(dfo, "datefmt_format: could not convert input " |
| 155 | + "into a date") |
| 156 | + } |
192 | 157 |
|
| 158 | + internal_format( dfo, timestamp, return_value TSRMLS_CC); |
193 | 159 | } |
194 | 160 |
|
195 | 161 | /* }}} */ |
|
0 commit comments