PEAR::Date_Timezone
| From: | Lukas Smith | Date: | Wed, 30 Apr 2003 21:44:31 +0000 |
| Subject: | PEAR::Date_Timezone | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-15753@lists.php.net to get a copy of this message | ||
Hi,
today I almost went insane when I finally tried to solve a bug that was
haunting me for days.
The problem seems that PEAR::Date_Timezone kills the timezone in the
inDaylightTime method due to its reliance on getenv('TZ'). Even if false
is return it overwrites the old setting of 'TZ' and since getenv('TZ')
did not work it cant restore the old 'TZ' setting.
I therefore propose the following additions to add the following line to
setDefault():
function setDefault($id)
{
global $default;
if(Date_TimeZone::isValidID($id)) {
+ if(!getenv('TZ')) putenv('TZ='.$id);
$default = $id;
}
}
I also added another fall back to also find dstshortname timezones to
the initialization. This is not a beautiful solution but there seems to
be no easy way to get the timezone. Windows still seems like a lost
cause in this regards however. Maybe the solution to
http://bugs.php.net/bug.php?id=22418 will help in
improving the
situation on windows:
if(isset($_DATE_TIMEZONE_DEFAULT)
&& Date_TimeZone::isValidID($_DATE_TIMEZONE_DEFAULT)
) {
Date_TimeZone::setDefault($_DATE_TIMEZONE_DEFAULT);
} elseif (getenv('PHP_TZ') &&
Date_TimeZone::isValidID(getenv('PHP_TZ'))) {
Date_TimeZone::setDefault(getenv('PHP_TZ'));
} elseif (getenv('TZ') && Date_TimeZone::isValidID(getenv('TZ'))) {
Date_TimeZone::setDefault(getenv('TZ'));
} elseif (Date_TimeZone::isValidID(date('T'))) {
Date_TimeZone::setDefault(date('T'));
} else {
- Date_TimeZone::setDefault('UTC');
+ $tz = 'UTC';
+ $tz_search = date('T');
+ foreach($GLOBALS['_DATE_TIMEZONE_DATA'] as $timezone)
+ {
+ if(isset($timezone['dstshortname']) && $timezone['dstshortname']
== $tz_search)
+ {
+ $tz = $timezone['shortname'];
+ break;
+ }
+ }
+ Date_TimeZone::setDefault($tz);
}
since we maintainers if this package seem to be less than active I don't
know how to handle this aside from doing a little vote on pear-dev. Then
again I can wait until after the pear-meeting on a commit.
regards,
Lukas Smith
smith@backendmedia.com
_______________________________
BackendMedia
www.backendmedia.com
berlin@backendmedia.com
Linn Zwoch Smith GbR
Pariser Str. 44
D-10707 Berlin
Tel +49 30 83 22 50 00
Fax +49 30 83 22 50 07