Binary Expressions

2008-10-14

Pear::Date Returned Timezone is Wrong

Filed under: — Adam @ 1:05 pm

Background Knowledge


I’m trying to determine the difference in minutes between two timestamps. I’m using Pear::Date to do this. The issue comes into play when I noticed that the wrong timezone was being used by Pear::Date, UTC. If I do not use Pear::Date the timezone is set correctly.

I have tried using date_default_timezone_set() and it does set the timezone back, however I feel this shouldn’t be necessary as the default timezone should be used. I have been using date_default_timezone_get() to determine what timezone is being used.

It’s my understanding that Pear::Date uses UTC when it is unable to determine the default timezone. As far as I know I have the default timezone set correctly and with a valid ID (see below). I was able to determine that the timezone changed from my default timezone to UTC after I used Date::setFromDateDiff(). This does not seem right at all.

I have checked the following.

  • Pear v1.7.2 stable
  • Pear::Date v1.4.7 stable
  • php.ini (default timezone) - date.timezone = “Canada/Saskatchewan”
  • phpinfo() - Correct configure file being loaded, /var/www/conf/php.ini.
  • phpinfo() - Under Date, date/time support is enabled.
  • phpinfo() - Default timezone - Canada/Saskatchewan
  • phpinfo() - date.timezone - Canada/Saskatchewan / Canada/Saskatchewan

PHP Code Test Case


1
2
3
4
5
6
7
8
9
require_once("Date.php");
 
$obFirstDate = new Date('20081014155640');
$obSecondDate = new Date(date("YmdHis",time()));
 
$obDateSpan = new Date_Span();
$obDateSpan->setFromDateDiff($obFirstDate, $obSecondDate);
echo (int)$obDateSpan->toMinutes();
echo "<br />".date_default_timezone_get();

Solution - Unknown


Does anyone have any suggestions where to look or what to do to fix this problem?

One Response to “Pear::Date Returned Timezone is Wrong”

  1. Thomas Says:

    Your code gives me the correct result, but it also sets the default time zone to UTC, like you wrote. The problem lies in the function inDaylightTime (Date/TimeZone.php:301). It works (and has been completely rewritten) in 1.5.0a1, but that has been in alpha for 7 months.

    To fix it in 1.4.7 you just have to comment out lines 310 and 312. This makes it reset the time zone environmental variable to blank if it was blank to begin with, which seems to me like a good thing. I don’t see any reasons for the if statement, and I’m pretty sure that it can’t have any side effects to remove it.

Leave a Reply

Take back your mailbox - CAUCE.org

Powered By Wordpress PHP: Hypertext Preprocessor MySQL Powered Download Juice, the cross-platform podcast receiver
Proud To Be Canadian Get Firefox Valid XHTML Valid CSS
<NO>OOXML Logo


25 queries. 0.378 seconds.
Copyright © 2004 - 2005 by Adam Douglas