Edit report at http://pear.php.net/bugs/bug.php?id=16520&edit=1

ID: 16520
Comment by: spencer@instantdelay.com
Reported By: spencer at instantdelay dot com
Summary: compare sometimes returns invalid result due to
standard time conversion
Status: Open
Type: Bug
Package: Date
Operating System: Windows XP Professional
Package Version: 1.5.0a1
PHP Version: 5.2.5
Roadmap Versions:
New Comment:

Sorry, I set the time zone incorrectly in my test script. Please use
these lines instead:


Previous Comments:

[2009-08-13 19:43:45] svanhoose

The Date::compare function uses incorrect logic to compare two dates.
It first gets the value of each date in days (without converting to
standard time). If the days are equal, it goes on to check hours,
minutes, etc. However, it uses getStandardHour, etc. for those
comparisons. This can cause problems for dates near day boundaries where
this conversion can cause the hours to rollover to the previous day.

2009-08-07 10:00:00 and
2009-08-07 00:00:00
(both in America/Los_Angeles)

The # of days are equal, so hours must be compared. For the first date
getStandardHour() returns 9. On the second date, getStandardHour()
returns 23. This causes compare to return that the 1st date is before
the 2nd.

Test script:
require_once 'Date.php';

$d1 = new Date("2009-08-07 10:00:00");
$d2 = new Date("2009-08-07 00:00:00");


$result = Date::compare($d1, $d2);
echo "Is " . $d1->getDate() . " before " . $d2->getDate() . " ?\n";
echo ($result < 0 ? "Yes" : "No");

Expected result:
The code should print No since obviously August 8th at 10 AM is not
before August 8th at 12 AM.

Actual result:
The code prints Yes.


Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
postedAug 13, '09 at 6:06p
activeAug 13, '09 at 6:06p

1 user in discussion

Spencer: 1 post



site design / logo © 2022 Grokbase