|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-07-26 17:45 UTC] jeremy at techtrav dot com
Description:
------------
the newest 5.1.X version of PHP does not seem to work with day light savings time. the Expected result was recieved from PHP 5.0.4
I am adding 6 days to Oct 25th to cross over daylight savings time on Oct 30th. There should be 25 hours in Oct 30th.
Reproduce code:
---------------
$date = strtotime('25 Oct');
echo date('m/d/Y H:m:s', $date+(86400*6));
Expected result:
----------------
10/30/2005 23:10:00
Actual result:
--------------
10/31/2005 00:10:00
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
Obviosly "6 days" is not equal to "86400*6", exactly because of daylight savings. Change this line: echo date('m/d/Y H:m:s', $date+(86400*6)); to echo date('m/d/Y H:m:s', strtotime("+6 days", $date));Please run this code with 5.0.4 and tell me what you get: <?php $date = strtotime('25 Oct'); var_dump(date('m/d/Y H:m:s', $date+(86400*6))); var_dump(date('m/d/Y H:m:s', strtotime("+6 days", $date))); ?>I unpacked both 5.0.4, 5.1.0b3 and the latest code to my Win XP box, and tried the following in command line: C:\devtool>php-5.1.0b3\php -r "echo date('r');" Thu, 04 Aug 2005 08:05:40 +0000 C:\devtool>php-5.0.4\php -r "echo date('r');" Thu, 04 Aug 2005 10:05:45 +0200 C:\devtool>php-latest\php -r "echo date('r');" Thu, 04 Aug 2005 08:10:33 +0000 I think the oly problem is that php doesn't read the timezone of the Operating system. regards, Czimiwell the problem comes when you cross the daylight savings time day of Oct 30th. Strtotime will handle the 25 hour day just great. Remebering there are 25 hours in Oct 30th is important. That is why when you run the following code in PHP 5.0.4 echo date('r', (strtotime('oct 25')+(86400*6))); you do get (which is right): Sun, 30 Oct 2005 23:00:00 -0600 an hour short of Oct 31st. However when you run that code in PHP 5.1.X you find that Oct 30th does not contain 25 hours. Mon, 31 Oct 2005 00:00:00 +0000 This difference will definitely screw up scripts that are particularly time sensitive, like my field of Travel.Look at the formatted date: Mon, 31 Oct 2005 00:00:00 +0000 It doesn't have a timezone offset, so it seems that "xczimi" is right. Does it help if you add: date_default_timezone_set("America/New_York") at the top of the script?I tried adding that line to the top of my code. I am not familar with that function nor do I find it in the documentation. I get a fatal error: Fatal error: Call to undefined function date_default_timezone_set() when I run this script: date_default_timezone_set("America/New_York"); echo date('r', (strtotime('oct 25')+(86400*6))); I would agree with you in your conclusion though that it would appear that PHP 5.1.X is not reading the timezone of the local machine.okay I figured out how to set my time zone. I ran the following code in PHP 5.0.4 and PHP 5.1.X and recieved the same result putenv("TZ=US/Central"); echo date('r', (strtotime('oct 25')+(86400*6))); This would mean the bug is simply that PHP5.1.X is not looking at the time zone on the local machine.hi it seems that I have a related problem: I am on GMT+1 for the following example the system time is 11:00 date("H:i"); => 09:00 set system time-zone to GMT(+0) date("H:i"); => 09:00 set system time to 10:00 date("H:i"); => 08:00 It seems that php don't have the correct timezone. This error occurs since 5.1.0b3. My box runs on win2000SP4 with the latest snapshot.to derick: actually its not that difficult to guess the timezone on windows (with the comming winfx api will be even easier). After some research on the web and some testing: #include <time.h> main () { time_t t; localtime ((time(&t), &t)); // fill the _tzname var printf("TZ=%s TZDST=%s\n", _tzname[0], _tzname[1]); } with GMT outputs: TZ=GMTST TZDST=GMTDT _tzname[0] is the timezone abbr name. _tzname[1] is filled if the current timezone has DST changes. more testing: Pacific time: TZ=PST TZDST=PDT Central time: TZ=CST TZDST=CDT Brasilia: TZ=ESAST TZDST=ESADT Brisbane: TZ=EAST TZDST= The problem here is that our DB doesn't have these abbreviations. But with some trialing we could all tz settings that windows uses and link them to the main db.A better program would be: #include <time.h> #include <stdio.h> main () { time_t t; struct tm *tstruct; tstruct = localtime ((time(&t), &t)); printf("TZ=%s TZDST=%s is_dst:%d\n", _tzname[0], _tzname[1], tstruct->tm_isdst); } is_dst is 0 if DST isn't in effect, or positive otherwise. Although you cannot get the precise tz info, you can get the timezone offset with ease. there is a nice example here: http://msdn.microsoft.com/library/en-us/vclib/html/_crt_time.asp but I can't test it, because cygwin's win32 api doesn't export some required structures (and I didn't installed MSVC yet).