summaryrefslogtreecommitdiff
path: root/ext/intl
diff options
context:
space:
mode:
Diffstat (limited to 'ext/intl')
-rwxr-xr-xext/intl/dateformat/dateformat_attr.c1
-rwxr-xr-xext/intl/dateformat/dateformat_format.c26
-rwxr-xr-xext/intl/dateformat/dateformat_parse.c13
-rwxr-xr-xext/intl/formatter/formatter_attr.c9
-rw-r--r--ext/intl/tests/bug50590.phpt13
-rwxr-xr-xext/intl/tests/dateformat_format.phpt138
-rwxr-xr-xext/intl/tests/dateformat_format_parse.phpt20
-rwxr-xr-xext/intl/tests/dateformat_get_locale.phpt6
-rwxr-xr-xext/intl/tests/dateformat_parse_timestamp_parsepos.phpt6
-rwxr-xr-xext/intl/tests/formatter_get_set_symbol.phpt7
10 files changed, 208 insertions, 31 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 );
}
/* }}} */
diff --git a/ext/intl/formatter/formatter_attr.c b/ext/intl/formatter/formatter_attr.c
index d9b67dda3..851b2b310 100755
--- a/ext/intl/formatter/formatter_attr.c
+++ b/ext/intl/formatter/formatter_attr.c
@@ -250,7 +250,7 @@ PHP_FUNCTION( numfmt_get_symbol )
long symbol;
UChar value_buf[4];
UChar *value = value_buf;
- int length = USIZE(value);
+ int length = USIZE(value_buf);
FORMATTER_METHOD_INIT_VARS;
/* Parse parameters. */
@@ -262,12 +262,17 @@ PHP_FUNCTION( numfmt_get_symbol )
RETURN_FALSE;
}
+
+ if(symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) {
+ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "numfmt_get_symbol: invalid symbol value", 0 TSRMLS_CC );
+ RETURN_FALSE;
+ }
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
length = unum_getSymbol(FORMATTER_OBJECT(nfo), symbol, value_buf, length, &INTL_DATA_ERROR_CODE(nfo));
- if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value )) {
+ if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value_buf )) {
++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */
INTL_DATA_ERROR_CODE(nfo) = U_ZERO_ERROR;
value = eumalloc(length);
diff --git a/ext/intl/tests/bug50590.phpt b/ext/intl/tests/bug50590.phpt
new file mode 100644
index 000000000..c39c333b2
--- /dev/null
+++ b/ext/intl/tests/bug50590.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Bug #50590 (IntlDateFormatter::parse result is limited to the integer range)
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+$fmt = new IntlDateFormatter("en_US", IntlDateFormatter::FULL, IntlDateFormatter::FULL);
+var_dump($fmt->parse("Wednesday, January 20, 2038 3:14:07 AM GMT"));
+
+?>
+--EXPECTF--
+%s(2147570047)
diff --git a/ext/intl/tests/dateformat_format.phpt b/ext/intl/tests/dateformat_format.phpt
index c4fed041d..e5548196d 100755
--- a/ext/intl/tests/dateformat_format.phpt
+++ b/ext/intl/tests/dateformat_format.phpt
@@ -33,8 +33,8 @@ function ut_main()
0,
-1200000,
1200000,
- 2200000000,
- -2200000000,
+ 2200000000.0,
+ -2200000000.0,
90099999,
3600,
-3600
@@ -70,6 +70,15 @@ function ut_main()
$localtime_arr2,
$localtime_arr3
);
+
+ $d1 = new DateTime("2010-01-01 01:02:03", new DateTimeZone("UTC"));
+ $d2 = new DateTime("2000-12-31 03:04:05", new DateTimeZone("UTC"));
+ $d2->setTimezone(new DateTimeZone("PDT"));
+ $dates = array(
+ $d1,
+ $d2,
+ new StdClass(),
+ );
//Test format with input as a timestamp : integer
foreach( $time_arr as $timestamp_entry){
@@ -111,6 +120,24 @@ function ut_main()
}
}
+ foreach($dates as $date_entry) {
+ foreach( $locale_arr as $locale_entry ){
+ foreach( $datetype_arr as $datetype_entry ) {
+ $res_str .= "\n------------";
+ $res_str .= "\nDate is: ".var_export($date_entry, true);
+ $res_str .= "\n------------";
+
+ $fmt = ut_datefmt_create( $locale_entry , $datetype_entry ,$datetype_entry, $timezone, IntlDateFormatter::GREGORIAN );
+ $formatted1 = ut_datefmt_format( $fmt , $date_entry);
+ if( intl_get_error_code() == U_ZERO_ERROR){
+ $res_str .= "\nFormatted DateTime is : $formatted1";
+ }else{
+ $res_str .= "\nError while formatting as: '".intl_get_error_message()."'";
+ }
+ }
+ }
+ }
+
return $res_str;
}
@@ -285,4 +312,109 @@ Formatted localtime_array is : Dec 17, 1895 12:13:11 AM
IntlDateFormatter locale= en_US ,datetype = 3 ,timetype =3
Formatted localtime_array is : 12/17/95 12:13 AM
IntlDateFormatter locale= en_US ,datetype = -1 ,timetype =-1
-Formatted localtime_array is : 18951217 12:13 AM \ No newline at end of file
+Formatted localtime_array is : 18951217 12:13 AM
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2010-01-01 01:02:03',
+ 'timezone_type' => 3,
+ 'timezone' => 'UTC',
+))
+------------
+Formatted DateTime is : Thursday, December 31, 2009 3:02:03 PM GMT-10:00
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2010-01-01 01:02:03',
+ 'timezone_type' => 3,
+ 'timezone' => 'UTC',
+))
+------------
+Formatted DateTime is : December 31, 2009 3:02:03 PM GMT-10:00
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2010-01-01 01:02:03',
+ 'timezone_type' => 3,
+ 'timezone' => 'UTC',
+))
+------------
+Formatted DateTime is : Dec 31, 2009 3:02:03 PM
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2010-01-01 01:02:03',
+ 'timezone_type' => 3,
+ 'timezone' => 'UTC',
+))
+------------
+Formatted DateTime is : 12/31/09 3:02 PM
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2010-01-01 01:02:03',
+ 'timezone_type' => 3,
+ 'timezone' => 'UTC',
+))
+------------
+Formatted DateTime is : 20091231 03:02 PM
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2000-12-30 19:04:05',
+ 'timezone_type' => 3,
+ 'timezone' => 'America/Los_Angeles',
+))
+------------
+Formatted DateTime is : Saturday, December 30, 2000 5:04:05 PM GMT-10:00
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2000-12-30 19:04:05',
+ 'timezone_type' => 3,
+ 'timezone' => 'America/Los_Angeles',
+))
+------------
+Formatted DateTime is : December 30, 2000 5:04:05 PM GMT-10:00
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2000-12-30 19:04:05',
+ 'timezone_type' => 3,
+ 'timezone' => 'America/Los_Angeles',
+))
+------------
+Formatted DateTime is : Dec 30, 2000 5:04:05 PM
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2000-12-30 19:04:05',
+ 'timezone_type' => 3,
+ 'timezone' => 'America/Los_Angeles',
+))
+------------
+Formatted DateTime is : 12/30/00 5:04 PM
+------------
+Date is: DateTime::__set_state(array(
+ 'date' => '2000-12-30 19:04:05',
+ 'timezone_type' => 3,
+ 'timezone' => 'America/Los_Angeles',
+))
+------------
+Formatted DateTime is : 20001230 05:04 PM
+------------
+Date is: stdClass::__set_state(array(
+))
+------------
+Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
+------------
+Date is: stdClass::__set_state(array(
+))
+------------
+Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
+------------
+Date is: stdClass::__set_state(array(
+))
+------------
+Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
+------------
+Date is: stdClass::__set_state(array(
+))
+------------
+Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
+------------
+Date is: stdClass::__set_state(array(
+))
+------------
+Error while formatting as: 'datefmt_format: object must be an instance of DateTime: U_ILLEGAL_ARGUMENT_ERROR'
diff --git a/ext/intl/tests/dateformat_format_parse.phpt b/ext/intl/tests/dateformat_format_parse.phpt
index eb4e98984..bd41d715b 100755
--- a/ext/intl/tests/dateformat_format_parse.phpt
+++ b/ext/intl/tests/dateformat_format_parse.phpt
@@ -187,16 +187,13 @@ Input timestamp is : 2200000000
IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
Formatted timestamp is : Monday, September 19, 2039 4:06:40 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The 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.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : 2200000000
IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
Formatted timestamp is : September 19, 2039 4:06:40 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The 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.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : 2200000000
IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
Formatted timestamp is : Sep 19, 2039 4:06:40 AM
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The 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.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : 2200000000
------------
Input timestamp is : -2200000000
@@ -204,16 +201,13 @@ Input timestamp is : -2200000000
IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
Formatted timestamp is : Sunday, April 15, 1900 5:53:20 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The 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.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : -2200000000
IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
Formatted timestamp is : April 15, 1900 5:53:20 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The 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.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : -2200000000
IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
Formatted timestamp is : Apr 15, 1900 5:53:20 AM
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The 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.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : -2200000000
------------
Input timestamp is : 90099999
@@ -297,4 +291,4 @@ Formatted localtime_array is : December 17, 1895 12:13:11 AM GMT+05:00
Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
Formatted localtime_array is : Dec 17, 1895 12:13:11 AM
-Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' , \ No newline at end of file
+Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
diff --git a/ext/intl/tests/dateformat_get_locale.phpt b/ext/intl/tests/dateformat_get_locale.phpt
index 262697261..17fcca355 100755
--- a/ext/intl/tests/dateformat_get_locale.phpt
+++ b/ext/intl/tests/dateformat_get_locale.phpt
@@ -29,6 +29,12 @@ function ut_main()
$res_str .= "\nAfter call to get_locale : locale= $locale";
$res_str .= "\n";
}
+ $badvals = array(100, -1, 4294901761);
+ foreach($badvals as $badval) {
+ if(ut_datefmt_get_locale($fmt, $badval)) {
+ $res_str .= "datefmt_get_locale should return false for bad argument $badval\n";
+ }
+ }
return $res_str;
diff --git a/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt b/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt
index fa4025737..b7e820388 100755
--- a/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt
+++ b/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt
@@ -76,8 +76,7 @@ Input text is : Sunday, September 18, 3039 4:06:40 PM PT
Locale is : en_US_CA
------------
datetype = 0 ,timetype =0
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The 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.: U_BUFFER_OVERFLOW_ERROR'
+Parsed text is : 33756908800
datetype = 1 ,timetype =1
Error while parsing as: 'Date parsing failed: U_PARSE_ERROR'
datetype = 2 ,timetype =2
@@ -117,8 +116,7 @@ Error while parsing as: 'Date parsing failed: U_PARSE_ERROR'
datetype = 3 ,timetype =3
Error while parsing as: 'Date parsing failed: U_PARSE_ERROR'
datetype = -1 ,timetype =-1
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The 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.: U_BUFFER_OVERFLOW_ERROR'
+Parsed text is : -2178601860
------------
Input text is : 19691218 08:49 AM
diff --git a/ext/intl/tests/formatter_get_set_symbol.phpt b/ext/intl/tests/formatter_get_set_symbol.phpt
index a1a430244..40bbd25ae 100755
--- a/ext/intl/tests/formatter_get_set_symbol.phpt
+++ b/ext/intl/tests/formatter_get_set_symbol.phpt
@@ -73,7 +73,12 @@ function ut_main()
// Restore attribute's symbol.
ut_nfmt_set_symbol( $fmt, $symb, $orig_val );
}
-
+ $badvals = array(2147483648, -2147483648, -1, 4294901761);
+ foreach($badvals as $badval) {
+ if(ut_nfmt_get_symbol( $fmt, 2147483648 )) {
+ $res_str .= "Bad value $badval should return false!\n";
+ }
+ }
return $res_str;
}