diff options
Diffstat (limited to 'ext/intl/dateformat')
| -rwxr-xr-x | ext/intl/dateformat/dateformat_attr.c | 1 | ||||
| -rwxr-xr-x | ext/intl/dateformat/dateformat_format.c | 26 | ||||
| -rwxr-xr-x | ext/intl/dateformat/dateformat_parse.c | 13 |
3 files changed, 32 insertions, 8 deletions
diff --git a/ext/intl/dateformat/dateformat_attr.c b/ext/intl/dateformat/dateformat_attr.c index 51012896e..7c6cef953 100755 --- a/ext/intl/dateformat/dateformat_attr.c +++ b/ext/intl/dateformat/dateformat_attr.c @@ -309,6 +309,7 @@ PHP_FUNCTION( datefmt_get_locale ) DATE_FORMAT_METHOD_FETCH_OBJECT; loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type,&INTL_DATA_ERROR_CODE(dfo)); + INTL_METHOD_CHECK_STATUS(dfo, "Error getting locale"); RETURN_STRING(loc, 1); } /* }}} */ diff --git a/ext/intl/dateformat/dateformat_format.c b/ext/intl/dateformat/dateformat_format.c index e41b38beb..4d03d924c 100755 --- a/ext/intl/dateformat/dateformat_format.c +++ b/ext/intl/dateformat/dateformat_format.c @@ -27,6 +27,7 @@ #include "dateformat_class.h" #include "dateformat_format.h" #include "dateformat_data.h" +#include "ext/date/php_date.h" /* {{{ * Internal function which calls the udat_format @@ -158,9 +159,30 @@ PHP_FUNCTION(datefmt_format) timestamp = internal_get_timestamp(dfo, hash_arr TSRMLS_CC); INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed" ) break; + case IS_OBJECT: { + zend_class_entry *date_ce = php_date_get_date_ce(); + zval retval; + zval *zfuncname; + if(!instanceof_function(Z_OBJCE_P(zarg), date_ce TSRMLS_CC)) { + intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: object must be an instance of DateTime", 0 TSRMLS_CC ); + RETURN_FALSE; + } + INIT_ZVAL(retval); + MAKE_STD_ZVAL(zfuncname); + ZVAL_STRING(zfuncname, "getTimestamp", 1); + if(call_user_function(NULL, &zarg, zfuncname, &retval, 0, NULL TSRMLS_CC) != SUCCESS || Z_TYPE(retval) != IS_LONG) { + intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: cannot get timestamp", 0 TSRMLS_CC ); + zval_ptr_dtor(&zfuncname); + RETURN_FALSE; + } + zval_ptr_dtor(&zfuncname); + p_timestamp = Z_LVAL(retval); + timestamp = p_timestamp*1000; + } + break; default: - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "datefmt_format: takes either an array or an integer timestamp value ", 0 TSRMLS_CC ); + intl_errors_set( INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, + "datefmt_format: takes either an array or an integer timestamp value or a DateTime object", 0 TSRMLS_CC ); RETURN_FALSE; } diff --git a/ext/intl/dateformat/dateformat_parse.c b/ext/intl/dateformat/dateformat_parse.c index c17089f1c..4193e8901 100755 --- a/ext/intl/dateformat/dateformat_parse.c +++ b/ext/intl/dateformat/dateformat_parse.c @@ -19,6 +19,7 @@ #endif #include <unicode/ustring.h> +#include <math.h> #include "php_intl.h" #include "intl_convert.h" @@ -35,7 +36,7 @@ */ 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; + double result = 0; UDate timestamp =0; UChar* text_utf16 = NULL; int32_t text_utf16_len = 0; @@ -52,12 +53,12 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" ); /* Since return is in sec. */ - result = (long )( timestamp / 1000 ); - if( result != (timestamp/1000) ) { - intl_error_set( NULL, U_BUFFER_OVERFLOW_ERROR, - "datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.\nThe valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.", 0 TSRMLS_CC ); + result = (double)timestamp / U_MILLIS_PER_SECOND; + if(result > LONG_MAX || result < -LONG_MAX) { + ZVAL_DOUBLE(return_value, result<0?ceil(result):floor(result)); + } else { + ZVAL_LONG(return_value, (long)result); } - RETURN_LONG( result ); } /* }}} */ |
