Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0a4

Bug #1180 Use of Date::inDaylightTime() switches date("r") from BST to GMT
Submitted: 2004-04-11 18:38 UTC
From: uklinux at modem-help dot com Assigned: pajoye
Status: Wont fix Package: Date
PHP Version: 4.2.2 OS: Linux 2.4.20-30.8.legacysmp
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 27 + 30 = ?

 
 [2004-04-11 18:38 UTC] uklinux at modem-help dot com
Description: ------------ $_DATE_TIMEZONE_DEFAULT="GB"; $today=new Date(); This is fine. date("r") will correctly report the current date in British Summer Time (the server is in the UK). Adding the line: $todayDST=($today->inDaylightTime())? "\$today has dst switched ON": "\$today has dst switched OFF"; to the top 2 lines will now cause date("r") to report the date in GMT. A live example page is at http://www.modem-help.com/bston.php (problem ON) and http://www.modem-help.com/bstoff.php (problem OFF). Reproduce code: --------------- $_DATE_TIMEZONE_DEFAULT="GB"; $today=new Date(); $todayDST=$today->inDaylightTime(); Date.php: v 1.27 2004/03/14 15:22:46 pajoye Exp $ TimeZone.php: v 1.5 2004/03/14 15:27:13 pajoye Exp $ Expected result: ---------------- date("r") to report the date in GMT (should be BST). Actual result: -------------- ./configure '--host=i386-redhat-linux' '--build=i386-redhat-linux' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--prefix=/usr' '--with-config-file-path=/etc' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-db3' '--with-curl' '--with-dom=/usr' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd' '--enable-gd-native-ttf' '--with-ttf' '--with-gdbm' '--with-gettext' '--with-ncurses' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-regex=system' '--with-xml' '--with-expat-dir=/usr' '--with-zlib' '--with-layout=GNU' '--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--without-oci8' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos=/usr/kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--with-pgsql=shared' '--with-snmp=shared,/usr' '--with-snmp=shared' '--enable-ucd-snmp-hack' '--with-unixODBC=shared' '--enable-memory-limit' '--enable-bcmath' '--enable-shmop' '--enable-versioning' '--enable-calendar' '--enable-dbx' '--enable-dio' '--enable-mcal' '--with-apxs2=/usr/sbin/apxs'

Comments

 [2004-05-16 13:12 UTC] paj at pearfr dot org
Please try either current cvs or upcoming 1.4.3 release. There was a problem in the TZ definitions (Bangladesh overrided UK one). --Pierre
 [2004-09-13 10:09 UTC] andrew at awarez dot net
I have the same problem, with the 1.4.3 release. It's currently BST in the UK, and when the comparing dates with $date1->before($date2), the timezone (as reported by date('T')) changes from "BST" to "UTC".
 [2004-11-23 00:04 UTC] jnareb at wp dot pl
The Date_TimeZone::inDaylightTime changes server timezone to UTC if TZ environmental variable is initially (before calling inDaylightTime) unset. It does this because it sets TZ to empty string (TZ='') if getenv('TZ') results in empty string, which means that TZ was initially empty or unset. TZ='' means that server should use default timezone, i.e. UTC (GMT), While when TZ is not set the server timezone is defined by other means (e.g. by setting ZONE variable in /etc/sysconfig/clock on Linux and/or copying the appropriate zoneinfo file to /etc/localtime (or /usr/share/zoneinfo/localtime)). I couldn't post/make the patch because I don't know how to check if environmental variable is not set, and how to unset the environmental variable. The offending code is (from Date-1.4.3) ------------ function inDaylightTime($date) { $env_tz = ""; if(getenv("TZ")) { $env_tz = getenv("TZ"); } putenv("TZ=".$this->id); $ltime = localtime($date->getTime(), true); putenv("TZ=".$env_tz); return $ltime['tm_isdst']; } ------------
 [2004-11-23 19:41 UTC] jnareb at wp dot pl
You can check if the environmental variable, e.g. TZ, is set via $_ENV superglobal array i.e. using either array_key_exists('TZ', $_ENV) or isset($_ENV['TZ']). Unfortunately PHP lacks unsetenv( string varname ) function, and modyfying $_ENV['TZ'] does not change environmental variables as seen e.g. by `date' function.
 [2005-07-30 15:44 UTC] paul at stunning-stuff dot com
Hi, When putenv (tries to) restore the TZ environment variable (line 9) after changing it to $this->id (line 7) it will be fine on systems that had the TZ environment variable to begin with, but on systems that did not have the TZ environment variable before it got changed (line 7) it will be set to '' (line 9) and PHP interprets this as GMT. The rest of the script will be executed with GMT being the local timezone. There is no way around this (without changing PHP internally). The only way to solve this imo is to have the user provide the local timezone in a constant and use that constant instead of $env_tz (line 9). 1 function inDaylightTime($date) 2 { 3 $env_tz = ""; 4 if(getenv("TZ")) { 5 $env_tz = getenv("TZ"); 6 } 7 putenv("TZ=".$this->id); 8 $ltime = localtime($date->getTime(), true); 9 putenv("TZ=".$env_tz); 10 return $ltime['tm_isdst']; 11 } Regards, Paul van der Maas --- www.stunning-stuff.com
 [2005-07-30 16:07 UTC] pierre at dotgeek dot org
Cannot be solved without BC. Do not mix php date and pear::date together. --Pierre
 [2005-07-30 23:10 UTC] paul at stunning-stuff dot com
What is BC exactly? I'm not sure what it is. Thanks, Paul van der Maas --- www.stunning-stuff.com
 [2005-12-12 15:38 UTC] nick at tesbo dot com
if have the same problem, i have CET. my $TZ environment variable is not set. everything works fine in CET until i call Date_Span::setFromDateDiff(). after that, date('T') returns GMT, which is not correct. $now = new Date(); echo "now: ". $now->format("%H"); // returns my correct local time. $span = new Date_Span(); $span->setFromDateDiff($now, $now); echo "now: ". $now->format("%H"); // returns time in GMT. what's wrong here? i'm willing to help! i use Date-1.4.6. nick