php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33871 No daylight savings time
Submitted: 2005-07-26 17:45 UTC Modified: 2005-08-13 01:00 UTC
Votes:8
Avg. Score:4.2 ± 1.0
Reproduced:6 of 8 (75.0%)
Same Version:2 (33.3%)
Same OS:2 (33.3%)
From: jeremy at techtrav dot com Assigned: derick (profile)
Status: No Feedback Package: Date/time related
PHP Version: 5.1.0b3 OS: Windows XP Apache 2
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-26 17:49 UTC] tony2001@php.net
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));
 [2005-07-26 17:53 UTC] jeremy at techtrav dot com
Actually I realize 86400*6 should not be right as my code displays below. It should give you back one hour short, however when I do add 86400*6 onto the day in PHP 5.1.X I am getting the exact 6 days out.  That would be a problem.  Again PHP 5.0.4 handles this correctly.
 [2005-07-26 17:56 UTC] tony2001@php.net
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)));
?>
 [2005-07-26 18:02 UTC] jeremy at techtrav dot com
you get the expected result:

string(19) "10/30/2005 23:10:00" string(19) "10/31/2005 00:10:00" 

However in PHP 5.1.X I get:
string(19) "10/31/2005 00:10:00" string(19) "10/31/2005 00:10:00" 

Which is wrong.
 [2005-07-26 18:05 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


>you get the expected result:
No, *I* get the expected result with both versions.
 [2005-07-26 18:12 UTC] jeremy at techtrav dot com
I have upgraded to the newest snap as you have requested and I am still getting the same results.  PHP 5.0.4 returns the correct time.  PHP 5.1.X returns the wrong time.  Could this be an operating system issue?  I am on Windows XP with Apache 2.
 [2005-07-26 18:16 UTC] tony2001@php.net
This could be also a timezone issue.
What's your TZ ?
 [2005-07-26 18:21 UTC] jeremy at techtrav dot com
I am Central Standard Time in MN and we are on Day light Savings time.
 [2005-08-04 10:11 UTC] xczimi at sztaki dot hu
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,
Czimi
 [2005-08-04 16:32 UTC] jeremy at techtrav dot com
well 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.
 [2005-08-04 16:43 UTC] derick@php.net
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?
 [2005-08-04 16:44 UTC] jeremy at techtrav dot com
Oh now I understand Czimi comment.  If PHP 5.1.X is not looking at the time zone on my XP box then it is not going to know that Oct 30th is daylight savings time.  I think Czimi is probably right, PHP 5.1.X is not looking at the time zone my my XP box.
 [2005-08-04 16:51 UTC] jeremy at techtrav dot com
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.
 [2005-08-04 16:53 UTC] derick@php.net
Now, if we can find a way how PHP can guess the correct timezone from your windows box (like it can do on most unices) that would be nice - but I think it's quite impossible.

BTW, if you use error_reporting(E_ALL) you'd have gotten a warning about this...
 [2005-08-04 16:54 UTC] derick@php.net
That function is only there in the snapshots, please try that instead. http://snaps.php.net (and pick latest cvs (5.1-dev) there).
 [2005-08-04 16:55 UTC] jeremy at techtrav dot com
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.
 [2005-08-04 17:01 UTC] jeremy at techtrav dot com
By the way I do have E_ALL turned on, on my machine.  After all I don't run my windows box with PHP in production.  I use my windows box for development. Our PHP production runs on OpenBSD servers.

I don't quite understand this comment of yours:

"Now, if we can find a way how PHP can guess the correct timezone from your windows box "

PHP 5.0.4 reads my TZ perfectly and gives you the expected result.  Why would PHP 5.1.X not be able to?
 [2005-08-05 12:53 UTC] nlopess@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

Sorry, but I've tested on windows and it works perfectly. Are you sure you are using an up-to-date snapshot? And that means PHP 5.1.0 beta 3 is old...
 [2005-08-05 13:30 UTC] joerg dot klein at ifsam dot lu
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.
 [2005-08-05 13:36 UTC] nlopess@php.net
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.
 [2005-08-05 13:55 UTC] nlopess@php.net
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).
 [2005-08-05 14:24 UTC] pajoye@php.net
This is datas from your system (or the version you use). The problem with windows is that there is many different datas in each single product version.

--Pierre
 [2005-08-13 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC