Bug #74355 [Opn]: DateInterval::format() with "%F" sometimes shows incorrect value by 1us

From: Date: Sat, 01 Apr 2017 06:31:57 +0000
Subject: Bug #74355 [Opn]: DateInterval::format() with "%F" sometimes shows incorrect value by 1us
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208248@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74355&edit=1

 ID:                 74355
 User updated by:    for-bugs at hnw dot jp
 Reported by:        for-bugs at hnw dot jp
 Summary:            DateInterval::format() with "%F" sometimes shows
                     incorrect value by 1us
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Any
 PHP Version:        7.1.3
 Block user comment: N
 Private report:     N

 New Comment:

Another example:

<?php
$dt1=new DateTime("2000-01-01 00:00:00");
$dt2=new DateTime("2006-01-02 03:04:05.000251");
$interval = $dt1->diff($dt2);
var_dump($interval->format("%R%Y-%M-%D %H:%I:%S.%F"));
/* Output: string(25) "+06-00-01 03:04:05.000250" */


Previous Comments:
------------------------------------------------------------------------
[2017-04-01 01:35:04] for-bugs at hnw dot jp

Description:
------------
From PHP 7.1.0, DateInterval::format() supports "%F" parameter which shows fraction of
DateInterval. However, sometimes "%F" prints incorrect value because of floating point
inaccuracy.

Test script:
---------------
<?php
$dt1=new DateTime("2000-01-01 00:00:00");
$dt2=new DateTime("2006-01-02 03:04:05.524287");
$interval = $dt1->diff($dt2);
var_dump($interval->format("%R%Y-%M-%D %H:%I:%S.%F"));


Expected result:
----------------
string(25) "+06-00-01 03:04:05.524287"

Actual result:
--------------
string(25) "+06-00-01 03:04:05.524286"


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74355&edit=1


Thread (6 messages)

« previous php.bugs (#208248) next »