Edit report at https://bugs.php.net/bug.php?id=63435&edit=1
ID: 63435 Updated by: [email protected] Reported by: miau dot jp at gmail dot com Summary: Datetime::format('u') sometimes wrong by 1 microsecond -Status: Open +Status: Assigned Type: Bug Package: Date/time related Operating System: Any PHP Version: 5.3.18 -Assigned To: +Assigned To: remi Block user comment: N Private report: N 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
