Use of date(), and therefore time(), in the PEAR Date class
| From: | Andrew Hill | Date: | Fri, 10 Sep 2004 17:14:38 +0000 |
| Subject: | Use of date(), and therefore time(), in the PEAR Date class | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-196323@lists.php.net to get a copy of this message | ||
Hi all,
I've run into a bit of a doozy that I can't seem to figure out.
I'm using the PEAR Date class to deal with some time/date requirements
for some code, and everything has been working (to the best of my
knowledge) really well, up until now.
I decided to extend my code test suite (using Simple Test,
http://www.lastcraft.com/simple_test.php), by
caluclating the execution
time. I did this by:
1) Creating a Date object at the start of the test suite, via "new
Date()";
2) Creating another Date object at the end of the test suite, via "new
Date()";
3) Creating a Date_Span object, via "new Date_Span()";
4) Setting the Date_Span object's span by using the
Date_Span::setFromDateDiff() method, with the two Date objects.
Finally, I can use the Date_Span object to output the time taken to run
the test suite, using the Date_Span::format() method.
However, this gave me a run time that was clearly wrong, so I started
looking into why, and discovered that the Date object I create at the
end of the test suite run is one hour earlier than the current time. I
have traced the code through the execution of the creation of the Date
objects, and it is correctly setting the time zone as UTC during the
creation of *both* Date objects -- however, as each Date object is
created with the code "new Date()", the PEAR Date class uses a call to
"date("Y-m-d H:i:s")" (and, by association, to "time()") in order to
get
the current time, and use it to set the properties of the Date object.
It is the call to PHP's date()/time() function that returns a time that
is one hour earlier than my system clock.
What I don't understand is *why* this is happening. If I call the time()
function directly before/after the creation of the second call to Date
(which is the one that generates the incorrect date), I actually get the
correct time!
Can anyone please suggest what might be causing date()/time() to
(sometimes) return an incorrect time inside the Date class?
Cheers,
--
Andrew Hill
Developer
Awarez Ltd.
Kirkman House, 12-14 Whitfield Street, London W1T 2RF
T: +44 (0)20 7299 7370 F: +44 (0)20 7299 7374