#40937 [Opn->Bgs]: date() lose Sundays
| From: | derick@php.net | Date: | Wed, 28 Mar 2007 19:11:01 +0000 |
| Subject: | #40937 [Opn->Bgs]: date() lose Sundays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-110894@lists.php.net to get a copy of this message | ||
ID: 40937
Updated by: derick@php.net
Reported By: ctrlaltca at libero dot it
-Status: Open
+Status: Bogus
Bug Type: Date/time related
Operating System: Slackware Linux
PHP Version: 5.2.1
New Comment:
We are happy to tell you that you just discovered Daylight Savings
Time. For more information see:
http://webexhibits.org/daylightsaving/b.html
Instead of using mktime/date consider using gmmktime and gmdate which
do
not suffer from DST.
Try this script instead, that also shows the time to see what's
happening:
<?php
$day=date("j");
$mo=date("n");
$year=date("Y");
for($i=6; $i>=0; $i--)
{
$a=mktime(0, 0, 0, $mo,$day, $year);
$b=date("r",$a);
$c=strtotime($b. "-" . $i . " day");
$curdate=date("Ymd His",$c);
$d=date("r");
$e=strtotime($d. "-" . $i . " day");
$curdate2=date("Ymd His",$e);
echo
"\n|".$b."=".$d."|".$c."=".$e."|".$curdate."=".$curdate2."|";
}
?>
Previous Comments:
------------------------------------------------------------------------
[2007-03-28 15:21:00] ctrlaltca at libero dot it
Description:
------------
It seems that the date() function "jumps over" sundays when converting
timestamps not referring to midnight.
Similar to #461
Reproduce code:
---------------
<?php
$day=date("j");
$mo=date("n");
$year=date("Y");
for($i=6; $i>=0; $i--)
{
$a=mktime(0, 0, 0, $mo,$day, $year);
$b=date("r",$a);
$c=strtotime($b. "-" . $i . " day");
$curdate=date("Ymd",$c);
$d=date("r");
$e=strtotime($d. "-" . $i . " day");
$curdate2=date("Ymd",$e);
echo
"\n|".$b."=".$d."|".$c."=".$e."|".$curdate."=".$curdate2."|";
}
?>
Expected result:
----------------
I expect this script to return the right "Ymd" dates of the last seven
days.
Actual result:
--------------
It works:
|Wed, 28 Mar 2007 00:00:00 +0200=Wed, 28 Mar 2007 17:13:37
+0200|1175032800=1175094817|20070328!=20070328|
but when it finds a sunday, dates are shifted off of 1 day:
|Wed, 28 Mar 2007 00:00:00 +0200=Wed, 28 Mar 2007 17:13:37
+0200|1174773600=1174835617|20070324!=20070325|
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40937&edit=1