From:             miau dot jp at gmail dot com
Operating system: Any
PHP version:      5.3.18
Package:          Date/time related
Bug Type:         Bug
Bug description:Datetime::format('u') sometimes wrong by 1 microsecond

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 bug report at https://bugs.php.net/bug.php?id=63435&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=63435&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=63435&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=63435&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=63435&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=63435&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=63435&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=63435&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=63435&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=63435&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=63435&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=63435&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=63435&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=63435&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63435&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=63435&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=63435&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=63435&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63435&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=63435&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=63435&r=mysqlcfg

Reply via email to