php-src/ext/intl/tests/msgfmt_millisecond_dates.phpt
Gustavo André dos Santos Lopes ac33e40d2a 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.
2012-05-13 23:03:07 +02:00

31 lines
788 B
PHP

--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==