Bug #68506 [Opn->Csd]: General DateTime improvments needed for microseconds to become useful

From: Date: Wed, 05 Oct 2016 20:05:43 +0000
Subject: Bug #68506 [Opn->Csd]: General DateTime improvments needed for microseconds to become useful
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204499@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68506&edit=1 ID: 68506 Updated by: derick@php.net Reported by: mfaust at usinternet dot com Summary: General DateTime improvments needed for microseconds to become useful -Status: Open +Status: Closed Type: Bug Package: Date/time related PHP Version: master-Git-2014-11-26 (Git) -Assigned To: +Assigned To: derick Block user comment: N Private report: N New Comment: The fix for this bug has been committed. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. For Windows: http://windows.php.net/snapshots/ Thank you for the report, and for helping us make PHP better. Fixed for PHP 7.1.0 RC4, except for your last point, as that would mean changing the signature of the function. Previous Comments: ------------------------------------------------------------------------ [2014-11-26 13:27:15] mfaust at usinternet dot com Description: ------------ There are several major issues with the current implementation of DateTime in regards to microseconds that make it generally useless as-is. Microseconds are critical for many reasons, including high resolution logging in todays environments. Here are a few additional observations made with microseconds in its current state: - They are not used for object comparisons. Internal comparisons should take microseconds into account. This is seen as a bug. - There is no way to change microseconds after object initialization. setTime should have an optional 4th parameter added, and modify() should also allow changing/setting of microseconds. - They are not available in DateTimeInterval objects created from a call to diff() or created directly. - Various date functions that use timestamps should be able to use the microseconds portion of the result from microtime(TRUE), for example date('Y-m-d H:i:s.u', microtime(TRUE)) Test script: --------------- //Proper date comparison $a = new DateTime('2014-11-01 00:00:00.000001'); $b = new DateTime('2014-11-01 00:00:00.000002'); if($a == $b){ //should not happen echo 'SAME'; }elseif($a < $b){ //should happen echo 'DIFFERENT' } //Ability to change microseconds $a->setTime(11, 30, 00, 123456); //Diff output $diff = $a->diff($b); echo $diff->u; ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68506&edit=1

« previous php.bugs (#204499) next »