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

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

-Summary: compare sometimes returns invalid
result due to standard time conversion
+Summary: Compare returns invalid result for
certain dates due to standard time conversion
-Operating System: Windows XP Professional
+Operating System: Irrelevant



Previous Comments:
------------------------------------------------------------------------

[2009-08-13 20:06:21] svanhoose

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

-----------
$d1->setTZByID("America/Los_Angeles");
$d2->setTZByID("America/Los_Angeles");

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

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

Description:
------------
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.
e.g.

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:
---------------
<?php
require_once 'Date.php';

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

$d1->setTZByID("UTC-0800");
$d2->setTZByID("UTC-8000");

$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 @
categoriesphp
postedSep 26, '09 at 4:32p
activeSep 26, '09 at 4:32p
posts1
users1
websitepear.php.net

1 user in discussion

Spencer: 1 post

People

Translate

site design / logo © 2022 Grokbase