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

 ID:                 63435
 Updated by:         r...@php.net
 Reported by:        miau dot jp at gmail dot com
 Summary:            Datetime::format('u') sometimes wrong by 1
                     microsecond
-Status:             Assigned
+Status:             Closed
 Type:               Bug
 Package:            Date/time related
 Operating System:   Any
 PHP Version:        5.3.18
 Assigned To:        remi
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of remi
Revision: 
http://git.php.net/?p=php-src.git;a=commit;h=c2554b4bb43700ae16db34d9706db1db85ec78a4
Log: Fixed Bug #63435 Datetime::format('u') sometimes wrong by 1 microsecond


Previous Comments:
------------------------------------------------------------------------
[2012-11-04 15:50:59] miau dot jp at gmail dot com

Description:
------------
When storing '015700' microseconds in a Datetime object,
Datetime::format('u') returns '015699'. This behavior is critical when
I use optimistic locking.

----
$datetime = Datetime::createFromFormat('u', '015700');
$datetime->format('u'); // => '015699'
----

Datetime objects hold microseconds as "double" type in C.
'015700' is held as 0.015699999999999998679. Datetime::format('u')
calls floor() and it returns .015699.
(see https://github.com/php/php-src/blob/PHP-5.3.18/ext/date/php_date.c#L1098 )


Test script:
---------------
$datetime = Datetime::createFromFormat('u', '015700');
$datetime->format('u');


Expected result:
----------------
015700

Actual result:
--------------
015699


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



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

Reply via email to