php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26009 mktime calc fails on specific dates
Submitted: 2003-10-27 14:43 UTC Modified: 2003-10-28 11:47 UTC
From: nic at nicskitt dot co dot uk Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.3.3 OS: Windows XP Pro SP1, IIS, ISAPI
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nic at nicskitt dot co dot uk
New email:
PHP Version: OS:

 

 [2003-10-27 14:43 UTC] nic at nicskitt dot co dot uk
Description:
------------
When performing the while loop shown in the code mktime function produces duplicate results on the following specific dates (2004-03-27) and (2003-03-29) and (2002-03-30). They all seem to be in the month of march. This starts afer 2001 and I havent yet checked how far it continues.

Because mktime is suppose to handle illegal days and therefore recalcuate the whole date I cant see why this would happen.



Reproduce code:
---------------
$starting = strtotime("2001-01-01");
$ending = strtotime("2005-01-01");
$newdate = $starting;
$day 	= date("d",$newdate);
$month 	= date("m",$newdate);
$year 	= date("Y",$newdate);

echo("Starting->".date("Y-m-d",$newdate)."<br>");
echo("Ending->".date("Y-m-d",$ending)."<br>");
$x = 0;
while($newdate<$ending){

	$newdate = mktime(0,0,0,$month,($day+$x),$year);
	$fulldate = date("Y-m-d",$newdate);
	echo($fulldate."<br>");
	$x ++;	
}

Expected result:
----------------
Relevant Areas...

2002-03-29
2002-03-30 <- just one as you would expect
2002-04-01
2002-04-02
2002-04-03
...skip output...
2003-03-27
2003-03-28
2003-03-29 <- Just one as you would expect
2003-03-31
2003-04-01

and so on...

Actual result:
--------------
Relevant Areas...

2002-03-28
2002-03-29
2002-03-30 
2002-03-30 <- Duplicate Date
2002-04-01
2002-04-02
...skip output...
2003-03-27
2003-03-28
2003-03-29
2003-03-29 <- Duplicate Date
2003-03-31
2003-04-01

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-28 11:47 UTC] sniper@php.net
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.

..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 14:01:29 2024 UTC