php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68506 General DateTime improvments needed for microseconds to become useful
Submitted: 2014-11-26 13:27 UTC Modified: 2016-10-05 20:05 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: mfaust at usinternet dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: master-Git-2014-11-26 (Git) OS:
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
20 - 2 = ?
Subscribe to this entry?

 
 [2014-11-26 13:27 UTC] 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;


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-05 20:05 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2016-10-05 20:05 UTC] derick@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 03:01:26 2024 UTC