php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74572 Wrong comparison result
Submitted: 2017-05-11 14:45 UTC Modified: 2017-05-11 16:03 UTC
From: bazillio07 at yandex dot ru Assigned: jhdxr (profile)
Status: Closed Package: date_time (PECL)
PHP Version: 7.0Git-2017-05-11 (Git) OS: OS X, Ubuntu
Private report: No CVE-ID: None
 [2017-05-11 14:45 UTC] bazillio07 at yandex dot ru
Description:
------------
For some reason when we compare 2 dates with 1 sec difference we got a bug in some PHP versions like: `5.6.30`, `7.0.0`, `7.1.16`. In some old verions it not persist in some new again is found.
The link with full test: https://3v4l.org/25phg

Test script:
---------------
<?php

function getTimezoneDate(DateTime $dateTime)
{
    return $dateTime->setTimezone(
        DateTime::createFromFormat('O', "+05:00")->getTimezone()
    );
}

$startDate = new DateTime('@' . 1451674800);

$startDate = getTimezoneDate($startDate);
$endDate = getTimezoneDate(new DateTime('@' . 1451847599));

$startDate->modify('+2 day');

$result1 = $startDate < $endDate;
$result2 = $startDate->getTimestamp() < $endDate->getTimestamp();

echo var_export($result1, true) . "\n" . var_export($result2, true);

Expected result:
----------------
```
false
false
```

Actual result:
--------------
```
true
false
```

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-11 16:03 UTC] jhdxr@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: jhdxr
 [2017-05-11 16:03 UTC] jhdxr@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 04:01:27 2019 UTC