Bug #68078 [Opn->Csd]: Datetime comparisons ignore microseconds

From: Date: Fri, 29 Jan 2016 14:33:20 +0000
Subject: Bug #68078 [Opn->Csd]: Datetime comparisons ignore microseconds
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198960@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68078&edit=1

 ID:                 68078
 Updated by:         derick@php.net
 Reported by:        stephen dot r dot burrows at gmail dot com
 Summary:            Datetime comparisons ignore microseconds
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Date/time related
 Operating System:   OS X 10.9.4
 PHP Version:        Irrelevant
-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.

Thanks Willem-Jan!


Previous Comments:
------------------------------------------------------------------------
[2014-09-22 19:50:20] stephen dot r dot burrows at gmail dot com

Description:
------------
Two datetimes with all values the same (except microseconds) always compare as "equal". To
put it another way, if you're trying to find out which one came first, you can't.

Test script:
---------------
$dt1 = new DateTime("2014-09-19 17:16:35.694274 America/Los_Angeles");
$dt2 = new DateTime("2014-09-19 17:16:35.728291 America/Los_Angeles");
var_dump($dt1 < $dt2);
# bool(false)
var_dump($dt1 == $dt2);
# bool(true)

# Not setting timezone because already have same timezone.
var_dump($dt1->format("Y-m-d H:i:s.u") < $dt2->format("Y-m-d
H:i:s.u"));
# bool(true)
var_dump($dt1->format("Y-m-d H:i:s.u") == $dt2->format("Y-m-d H:i:s.u"));
# bool(false)

Expected result:
----------------
The smaller datetime should compare as less than the larger one. To put this another way, the
comparison of the objects should be the same whether you're comparing them as objects or as
strings (and the string version is clearly correct IMO.)



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



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


Thread (2 messages)

« previous php.bugs (#198960) next »