php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2424 date() function missing a day after Oct. 31, 1999
Submitted: 1999-10-02 18:11 UTC Modified: 1999-10-02 21:09 UTC
From: Ron at RLT dot COM Assigned: jah (profile)
Status: Closed Package: Misbehaving function
PHP Version: 3.0.12 OS: Linux 2.2.6 (slackware)
Private report: No CVE-ID: None
 [1999-10-02 18:11 UTC] Ron at RLT dot COM
This code snippet generates a correct date for Saturdays in Oct., but then
starts listing dates for Friday starting in Nov. on through March of next year, then in Apr. 2000 starts reporting Saturday dates again. Changing the date() function to gmdate() corretly lists only dates for Saturdays through next year.:

 $secinday = 60 * 60 * 24; // seconds in a day
 $secinweek = $secinday * 7; // seconds in a week
 $thisday = date("w");
 $daystillsat = 6 - $thisday;
 $shipdate = ($daystillsat * $secinday) + mktime(0,0,0,10,02,1999);
 for($i=0; $i < 52; $i++) {
   print (date(" M d, Y \n",$shipdate) );
   $shipdate += $secinweek;
 } // end for           


PHP 3.0.12 compiled as a statically linked module to Apache 1.3.6
No other modules compiled in. PHP is standard "out-of-the-box" with no modifications to the default setup other than the install path.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-10-02 21:09 UTC] jah at cvs dot php dot net
You have forgotten to consider the effects of daylight saving time. mktime()'s
arguments are expressed in local time, and it returns the offset in seconds
from epoch (Jan 1 1970 00:00:00 GMT). Let's take an example and assume
that your local timezone is EST5EDT.

On line 5, mktime returns 938836800. (We'll just forgot $daystillsat *
$secinday, they are not relevant to the explanation). Note that this date falls
inside the daylight savings time. Now, let's assume that the DST stops on the
night between 30 and 31 Oct and all the clock are skewed one hour backward.
This will result as Nov 6 1999 00:00:00 your local time being 941864400
seconds off from epoch. But, $shipdate has been increment 5 times by
604800 (seconds in a week) and is now just 941860800, which falls on the
previous day at 23:00.

Maybe you should use mktime(12,0,0,10,02,1999). The possibility of DST
being 12 hours off from the normal time is enough small not to be considered...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 12:01:34 2024 UTC