com php-src: Keep date precision in MessageFormatter.: UPGRADING ext/intl/msgformat/msgformat_helpers.cpp ext/intl/tests/m
sgfmt_millisecond_dates.phpt
| From: | Gustavo André dos Santos Lopes | Date: | Sun, 13 May 2012 21:03:07 +0000 |
| Subject: | com php-src: Keep date precision in MessageFormatter.: UPGRADING ext/intl/msgformat/msgformat_helpers.cpp ext/intl/tests/m sgfmt_millisecond_dates.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-69059@lists.php.net to get a copy of this message | ||
Commit: ac33e40d2ae7288f66f5e3d56e7ae8e3f0266144
Author: Gustavo André dos Santos Lopes <cataphract@php.net> Sun, 6 May 2012
13:06:44 +0200
Parents: f09961cbe5879df40e5fc9d6d424896caf2a6f64
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ac33e40d2ae7288f66f5e3d56e7ae8e3f0266144
Log:
Keep date precision in MessageFormatter.
MessageFormatter::parse and MessageFormat::format (and their static
equivalents) now don't throw away better than second precision in the
arguments.
It's already bad enough that in MessageFormatter and IntlDateFormatter we
use seconds since epoch instead of milliseconds since epoch, deviating
from the ICU date representations. But we don't need to throw away extra
precision when parsing dates; we can keep the seconds since epoch
convention and return non integer doubles with only a small BC impact.
Note that we already could return doubles from MessageFormatter::parse if
the date was sufficiently in the past or in the future.
Changed paths:
M UPGRADING
M ext/intl/msgformat/msgformat_helpers.cpp
A ext/intl/tests/msgfmt_millisecond_dates.phpt
Diff:
diff --git a/UPGRADING b/UPGRADING
index 9f76366..1643bdd 100755
--- a/UPGRADING
+++ b/UPGRADING
@@ -57,6 +57,9 @@ PHP X.Y UPGRADE NOTES
- MessageFormatter::format() and related functions now don't error out when
an insufficient argument count is provided. Instead, the placeholders will
remain unsubstituted.
+- MessageFormatter::parse() and MessageFormat::format() (and their static
+ equivalents) now don't throw away better than second precision in the
+ arguments.
========================================
5. New Functions
diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp
index 42c5466..f8228df 100755
--- a/ext/intl/msgformat/msgformat_helpers.cpp
+++ b/ext/intl/msgformat/msgformat_helpers.cpp
@@ -665,11 +665,7 @@ U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args,
UC
switch(fargs[i].getType()) {
case Formattable::kDate:
aDate = ((double)fargs[i].getDate())/U_MILLIS_PER_SECOND;
- if(aDate > LONG_MAX || aDate < -LONG_MAX) {
- ZVAL_DOUBLE((*args)[i], aDate<0?ceil(aDate):floor(aDate));
- } else {
- ZVAL_LONG((*args)[i], (long)aDate);
- }
+ ZVAL_DOUBLE((*args)[i], aDate);
break;
case Formattable::kDouble:
diff --git a/ext/intl/tests/msgfmt_millisecond_dates.phpt
b/ext/intl/tests/msgfmt_millisecond_dates.phpt
new file mode 100644
index 0000000..6d6cf20
--- /dev/null
+++ b/ext/intl/tests/msgfmt_millisecond_dates.phpt
@@ -0,0 +1,31 @@
+--TEST--
+MessageFrormatter parses and formats dates with millisecond precision
+--SKIPIF--
+<?php
+if (!extension_loaded('intl'))
+ die('skip intl extension not enabled');
+--FILE--
+<?php
+exec('pause');
+ini_set("intl.error_level", E_WARNING);
+//ini_set("intl.default_locale", "nl");
+date_default_timezone_set('Europe/Lisbon'); //ignored for now, see bug #58756
+
+$d = 1336308097.123;
+$mf = new MessageFormatter('en_US',
+ "On {0,time,yyyy-MM-dd G 'at' HH:mm:ss.SSS zzz} something odd happened");
+
+var_dump($mf->format(array(1336310569.123)));
+
+$p = 'On 2012-05-06 AD at 15:22:49.123 GMT+02:00 something odd happened';
+var_dump($mf->parse($p));
+
+?>
+==DONE==
+--EXPECTF--
+string(%d) "On 2012-05-0%d AD at %d:%d:49.123 %s something odd happened"
+array(1) {
+ [0]=>
+ float(1336310569.123)
+}
+==DONE==
\ No newline at end of file