]> granicus.if.org Git - php/commitdiff
MessageFormatter accepts IntlCalendar arguments
authorGustavo André dos Santos Lopes <cataphract@php.net>
Thu, 17 May 2012 15:45:15 +0000 (17:45 +0200)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Thu, 17 May 2012 15:57:37 +0000 (17:57 +0200)
Now MessageFormatter::format() accepts IntlCalendar objects to be used in
arguments of type Format::kDate.

ext/intl/msgformat/msgformat_helpers.cpp
ext/intl/tests/msgfmt_format_intlcalendar.phpt [new file with mode: 0644]

index 84c6f40c18f873c77f111eb118a04a9fe3fbcedc..6f4615e1697049b28d9b3e68f9e213a670f7d48b 100755 (executable)
@@ -28,6 +28,7 @@
 #include <unicode/ustdio.h>
 #include <unicode/timezone.h>
 #include <unicode/datefmt.h>
+#include <unicode/calendar.h>
 
 #include <vector>
 
@@ -39,6 +40,8 @@ extern "C" {
 #include "msgformat_format.h"
 #include "msgformat_helpers.h"
 #include "intl_convert.h"
+#define USE_CALENDAR_POINTER 1
+#include "../calendar/calendar_class.h"
 /* avoid redefinition of int8_t, already defined in unicode/pwin32.h */
 #define _MSC_STDINT_H_ 1
 #include "ext/date/php_date.h"
@@ -134,6 +137,14 @@ static double umsg_helper_zval_to_millis(zval *z, UErrorCode *status TSRMLS_DC)
                                rv = U_MILLIS_PER_SECOND * (double)Z_LVAL(retval);
                        }
                        zval_ptr_dtor(&zfuncname);
+               } else if (instanceof_function(Z_OBJCE_P(z), Calendar_ce_ptr TSRMLS_CC)) {
+                       Calendar_object *co = (Calendar_object *)
+                               zend_object_store_get_object(z TSRMLS_CC );
+                       if (co->ucal == NULL) {
+                               *status = U_ILLEGAL_ARGUMENT_ERROR;
+                       } else {
+                               rv = (double)co->ucal->getTime(*status);
+                       }
                } else {
                        /* TODO: try with cast(), get() to obtain a number */
                        *status = U_ILLEGAL_ARGUMENT_ERROR;
diff --git a/ext/intl/tests/msgfmt_format_intlcalendar.phpt b/ext/intl/tests/msgfmt_format_intlcalendar.phpt
new file mode 100644 (file)
index 0000000..6ae78a9
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+MessageFormat accepts IntlCalendar args
+--SKIPIF--
+<?php
+if (!extension_loaded('intl'))
+       die('skip intl extension not enabled');
+--FILE--
+<?php
+ini_set("intl.error_level", E_WARNING);
+//ini_set("intl.default_locale", "nl");
+ini_set('date.timezone', 'Europe/Lisbon');
+
+$cal = new IntlGregorianCalendar(2012,04,17,17,35,36);
+
+$msgf = new MessageFormatter('pt_PT', '{0,date,full} {0,time,h:m:s a V}');
+echo $msgf->format(array($cal)), "\n";
+
+//NOT FIXED:
+/*$msgf = new MessageFormatter('en_US',
+'{1, select, date {{0,date,full}} other {{0,time,h:m:s a V}}}');
+
+echo "msgf2: ", $msgf->format(array($time, 'date')), " ",
+               $msgf->format(array($time, 'time')), "\n";
+*/
+
+?>
+==DONE==
+--EXPECT--
+Quinta-feira, 17 de Maio de 2012 5:35:36 p.m. WEST
+==DONE==
\ No newline at end of file