php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74298 IntlDateFormatter->format() doesn't return microseconds/fractions
Submitted: 2017-03-23 14:21 UTC Modified: 2017-03-25 11:23 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: jh at ht-studios dot de Assigned:
Status: Closed Package: intl (PECL)
PHP Version: 7.1.3 OS: Ubuntu 16.04 (puphpet)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jh at ht-studios dot de
New email:
PHP Version: OS:

 

 [2017-03-23 14:21 UTC] jh at ht-studios dot de
Description:
------------
PHP's IntlDateFormatter/IntlDateFormatter->format() returns zeros instead of Fractional Seconds: http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details

$ aptitude search '~i icu'
i A libicu52             - International Components for Unicode

Test script:
---------------
<?php
echo "All 3 should show the fractions of second:\n";

echo var_dump((new \DateTime())->format('Y-m-d\TH:i:s.u'));

echo var_dump((new \IntlDateFormatter(
    'en-US',
    \IntlDateFormatter::FULL,
    \IntlDateFormatter::FULL,
    'UTC',
    \IntlDateFormatter::GREGORIAN,
    'yyyy-MM-dd HH:mm:ss.SSSSSS'
))->format(new \DateTime()));

echo var_dump(datefmt_create(
    'en-US',
    \IntlDateFormatter::FULL,
    \IntlDateFormatter::FULL,
    'UTC',
    \IntlDateFormatter::GREGORIAN,
    'yyyy-MM-dd HH:mm:ss.SSSSSS'
)->format(new \DateTime()));


Expected result:
----------------
Microseconds should be outputted correctly.

Actual result:
--------------
Instead you get '000000`'

See: https://3v4l.org/3pMtR

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-24 16:28 UTC] andrew dot nester dot dev at gmail dot com
Thanks for pointing the issue! I just added PR for it.
To clarify a little bit - as documentation after you link says:

"Appends zeros if more than 3 letters specified. Truncates at three significant digits when parsing."
So it's possible to show only milliseconds (3 digits of fraction)
 [2017-03-25 11:23 UTC] cmb@php.net
-Package: *General Issues +Package: intl
 [2017-04-09 10:57 UTC] nikic@php.net
Automatic comment on behalf of andrew.nester.dev@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1ce355abb648dc6814ddd00876085617a946396f
Log: Fixed #74298 - IntlDateFormatter-&gt;format() doesn't return microseconds/fractions
 [2017-04-09 10:57 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC