php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14635 last week in october Monday displays twice!
Submitted: 2001-12-20 20:36 UTC Modified: 2001-12-20 20:47 UTC
From: jberall at yahoo dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.0.6 OS: Windows 2000 Professional
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
11 + 4 = ?
Subscribe to this entry?

 
 [2001-12-20 20:36 UTC] jberall at yahoo dot com
When iterating from a start mktime to another using the date() function the First Day of the Last Week in October messes up.

The same problem appears when using Apache or IIS.

Just cut and paste below to see what I mean.

<?php
	$today = getdate(mktime (0,11,0,10,1,2001));

	print "Notice Problem with October<br>".full_calendar_month ($today,$PHP_SELF, null);
	$today = getdate();
	print "Notice No Problem<br>".full_calendar_month ($today,$PHP_SELF, null);


/*
	DISPLAY A FULL MONTH CALENDAR
*/

function full_calendar_month ($today,$url, $arrevent) {
GLOBAL $cbouser;
$user = null;
	if ($cbouser) {	$user = "&cbouser=$cbouser";}//display the userid
	if (!$today) {$today = getdate();}
	//NEED TO CONVERT $today to midnight!
	$today = getdate(mktime(0,0,0,$today["mon"],$today["mday"],$today["year"]));
	$mktoday = mktime (0,0,0,$today["mon"],1,$today["year"]);
	$mkday = 86400;			//1 day in mktime 24 hr * 60 min * 60 sec.
	$fday = date("w",$mktoday);	//first day of the month w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) 
	$mth_num = date("n",$mktoday);	//the month number ie. Nov 11
	$cell_bgcolor = "#C0C0C0";
	/*
		DETERMINE THE FIRST DAY OF THE MONTH
	*/
	if ($fday == 0) {	//SUNDAY NEED TO GET TO MONDAY
		$mkstart = $mktoday - $mkday * 6;
	} elseif ($fday != 1) {//need to make the last part of last week.
		$mkstart = $mktoday - $mkday * ($fday-1);
	} else {	//THE MONTH STARTS WITH MONDAY
		$mkstart = $mktoday;
	}
	
	//FIND THE LAST DAY OF THE MONTH
	$mkend = $mktoday + $mkday * (date("t",$mktoday)-1);	//t - number of days in the given month; i.e. "28" to "31" 

	if (date("w",$mkend) != 0) {$mkend = $mkend + $mkday * (7-date("w",$mkend));}
	#echo date("w D M j Y ",$mkend)."<br>";
	
	//BEGIN THE OUTPUT
	/* FOR DROP BOX
	<select size=\"1\" name=\"month_now\" size=\"1\">".month_dropbox($mth_num)."</select> &nbsp;
	<select size=\"1\" name=\"year_now\" size=\"1\">".year_dropbox(date("Y",$mktoday))."
	&nbsp;<input type=\"submit\" name=\"submit\" value=\"Go\">
	*/
	
	 $table = "<table border=\"1\" width=\"100%\">
	 	        <tr><th><input type=\"submit\" name=\"submit\" value=\"<<\"></th>
	 	        <th colspan=\"4\" align=\"center\">".date("F Y",$mktoday)."        	
	 	        </th><th><input type=\"submit\" name=\"submit\" value=\">>\"></th></tr>
		<tr><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Sat/Sun</th></tr>";
	//SHADE THE DAYS THAT ARE NOT IN THE MONTH
	if ($today[0] == $mkstart) { 
		$bgcolor = "bgcolor=\"#FFFF00\" bordercolor=\"#FF0000\"";
	} elseif ($mth_num != date("n",$mkstart)) { 
		$bgcolor = "bgcolor=\"$cell_bgcolor\""; 
	} else {
		$bgcolor = "";
	}
	$event_date = "<a href=\"$url?event_date=".date("Y-m-d",$mkstart)."&rdocalendar_view=30$user\">".date("F j",$mkstart)."</a>";
	//THE FIRST DAY
	 $table .= "<tr><td align=\"right\" valign=\"top\" $bgcolor>$event_date</td>";

	for ($i=$mkstart+$mkday;$i<$mkend;$i+=$mkday) {
		$event_date = "event_date=".date("Y-m-d",$i)."&rdocalendar_view=30$user";
		//background color
		if ($today[0] == $i) { 
			$bgcolor = "bgcolor=\"#FFFF00\" bordercolor=\"#FF0000\" border=1";
		} elseif ($mth_num != date("n",$i)) { 
			$bgcolor = "bgcolor=\"$cell_bgcolor\" border=0"; 
		} else {
			$bgcolor = "";
		}
		//date display
		if (date("j",$i) == 1) { $the_day = date("F j",$i); } else { $the_day = date("j",$i);}
		
		switch (date("w",$i)) {	// day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) 
			case 1:		#monday
				$table .= "<tr><td align=\"right\" valign=\"top\" $bgcolor><a href=\"$url?$event_date\">$the_day</a></td>";
				break;
			case 6:		#saturday - sunday
				$table .= "<td>
						<table width=100% $bgcolor>
							<tr><td align=\"right\" valign=\"top\"><a href=\"$url?$event_date\">$the_day</a></td></tr>
						</table>";
				$i+=$mkday;
				//background color
				if ($today[0] == $i) { 
					$bgcolor = "bgcolor=\"#FFFF00\" bordercolor=\"#FF0000\" border=1";
				} elseif ($mth_num != date("n",$i)) { 
					$bgcolor = "bgcolor=\"$cell_bgcolor\" border=0"; 
				} else {
					$bgcolor = "";
				}
				$event_date = "event_date=".date("Y-m-d",$i)."&rdocalendar_view=30$user";
				//date display
				if (date("j",$i) == 1) { $the_day = date("F j",$i); } else { $the_day = date("j",$i);}
				#SUNDAY
				$table .= "<table width=100% $bgcolor>
					<tr>
						<td align=\"right\" valign=\"top\">
						<hr><a href=\"$url?$event_date\">$the_day</a></td></tr></table></td></tr>";
				break;
			default:	#tuesday - friday
				$table .= "<td align=\"right\" valign=\"top\" $bgcolor><a href=\"$url?$event_date\">$the_day</a></td>";
				break;
		}

	}
	$table .= "</table>";
	return $table;
}
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-20 20:47 UTC] jimw@php.net
october 28 was 25 hours long. daylight savings time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 23:01:34 2024 UTC