#14391 [Com]: gmmktime, gmdate work incorrect
| From: | keath at keathmilligan dot net | Date: | Sat, 19 Apr 2003 03:31:10 +0000 |
| Subject: | #14391 [Com]: gmmktime, gmdate work incorrect | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-37891@lists.php.net to get a copy of this message | ||
ID: 14391
Comment by: keath at keathmilligan dot net
Reported By: pilots at farlep dot net
Status: No Feedback
Bug Type: Date/time related
Operating System: Windows 2000 Server
PHP Version: 4.0.6
New Comment:
This is not just a Windows bug. It happens on Linux as well. It looks
like gmmktime() is getting confused trying to apply some sort of
daylight-savings logic. For me, gmmktime returns the correct results
except for 2AM, April 6th which happens to be the start of daylight
savings time in the US.
The following code:
$t=gmmktime(1,0,0,4,6,2003);
echo "<br>inside DST: ",gmdate("Y-m-d H:i",$t);
$t=gmmktime(2,0,0,4,6,2003);
echo "<br>inside DST: ",gmdate("Y-m-d H:i",$t);
$t=gmmktime(3,0,0,4,6,2003);
echo "<br>inside DST: ",gmdate("Y-m-d H:i",$t);
Yields:
inside DST: 2003-04-06 01:00
inside DST: 2003-04-06 03:00
inside DST: 2003-04-06 03:00
Previous Comments:
------------------------------------------------------------------------
[2003-04-07 10:52:26] f dot vulto at re-base dot com
Same problem with PEAR Date TimeZone. When converting datetimes to
local timezones in Europe, PHP calculates a Daylight Savings Time (DST)
starting at 2003-04-06 (= USA standard = first Sunday of April). What
should've been calculated is a DST starting at 2003-03-30 (= Europe
standard = last Sunday of March).
I think this can be deduced to 'mktime()' or 'localtime()' not working
correctly with 'TZ' environment variable on Windows:
<?php
$tzBackup = (getenv('TZ')) ? getenv('TZ') : '';
putenv('TZ=CET+1CEST');
print '<pre>';
$aTime = localtime(mktime(12, 0, 0, 3, 23, 2003, -1), 1);
print_r($aTime);
$aTime = localtime(mktime(12, 0, 0, 3, 30, 2003, -1), 1);
print_r($aTime);
$aTime = localtime(mktime(12, 0, 0, 4, 6, 2003, -1), 1);
print_r($aTime);
print '</pre>';
putenv('TZ=' . $tzBackup);
?>
'tm_isdst' should've been '1' for the second date (March 30), but is
'0' on my pc. This is probably because the Microsoft '_tzset' routine
doesn't know about regional DST differences. You can specify 'dzn' in
'set TZ=tzn[+|-]hh[:mm[:ss]][dzn]', but Microsoft manual says:
"The C run-time library assumes the United States's rules for
implementing the calculation of Daylight Saving Time (DST)" (see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt__tzset.asp)
which implies the exact value of 'dzn' ('CEST' in the example above) is
ignored, which is what I'm experiencing. Windows seems to calculate
the Daylight Saving Time with a fixed algorithm which is only true for
the US but not for Europe. The result is the DST will start at wrong
days.
Does this mean - using Windows - you can *only* calculate the exact
local time of a UTC time in a different timezone if this timezone is:
1. the local timezone of the server or
2. a timezone following US DST rules?
If so, instead of TZ, PHP has to use Windows API functions and registry
information to perform timezone conversions on a Windows platform. I
don't have PHP core coding experience so here are some useful links
:-)
http://archive.devx.com/premier/mgznarch/vbpj/1999/08aug99/mt0899.pdf
http://17slon.com/gp/gp/files/gptimezone.htm
http://www.thedelphimagazine.com/samples/1175/1175.htm
Freddy Vulto
------------------------------------------------------------------------
[2003-02-27 08:06:43] nospam at no-spam dot com
The gmmktime() & windows problem still persists on 4.3.0.
We now go into the third year of this bug being around. Could this
become a record???
Testcase:
gmmktime(0,0,0,1,1,1970);
MUST return 0, also on a win box that is not in GMT-Zone.
Or then, PLEASE introduce URGENTLY a new function that allows the
manual correction of the TZ, e.g.:
int gmmktime ( int hour, int minute, int second, int month, int day,
int year [, int is_dst] [, int tz_offset])
because it boils down to the fact that the TZ-offset is the thing that
is not detected correctly.
------------------------------------------------------------------------
[2003-01-12 05:41:11] frodo at interport dot net
this bug has been around for over 2 years and it's a big one!!!
for time based apps lets face it, the gmmktime function is extremely
important.
any idea when this will be fixed?
------------------------------------------------------------------------
[2003-01-08 02:13:31] napetune at hotmail dot com
I use Win2K.I got this problem too. But after I updated to php 4.2.1
version, they are gone. It works well on php 4.2.1 (or higher version,
I guess).
Kae
------------------------------------------------------------------------
[2002-12-12 09:03:48] moonset at hotmail dot com
Same problem - runing at the same time 2 systems:
On Windows NT 5.0 build 2195 PHP 4.1.1 on GMT zone:
echo (gmdate("U") . "<br>"); //1039704601
echo (date ("U") . "<br>"); //1039704601
echo (mktime() . "<br>"); //1039704601
echo (gmmktime() . "<br>"); //1039701001
echo (time() . "<br>"); //1039704601
On Linux webdev 2.4.19 #1 PHP 4.2.2 on EDT zone:
echo (gmdate("U") . "<br>"); //1039704601
echo (date ("U") . "<br>"); //1039704601
echo (mktime() . "<br>"); //1039704601
echo (gmmktime() . "<br>"); //1039686601
echo (time() . "<br>"); //1039704601
Peter
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/14391
--
Edit this bug report at http://bugs.php.net/?id=14391&edit=1