Re: pear calendar

From: Date: Sun, 16 May 2004 23:17:56 +0000
Subject: Re: pear calendar
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-12531@lists.php.net to get a copy of this message
Thanks for your help. You answered my second question fine. I could be wrong but I don't think there is supposed to be a year 0. Just from year 1 BCE to year 1 CE; but my understanding may be wrong. but that doesn't matter here. I've tried out year 0 in the calendar and that also works fine. Ok, I will try to rephrase what I said. As for the source, it is 193 lines and so...well I'll post that at the bottom. you can look at it if you don't understand my question still after I explain it here. I have four links at the bottom of my page which say next month, previous month, next year and previous year. Now, say that I have displayed in the calendar January of 2004. I have that split up into weeks in my table, and according to that the first day of January is on a Thursday. Now obviously, the 31 of December must be on a wednesday; but when I click the previous month link, which makes the url look like: calendars.php?month=0&year=2004&start_day=0 and I use adjust in my code as you will see in the code at the bottom, to be december of 2003, it shows December 31 as landing on a Monday. However, if I go to the page: calendar.php?month=12&year=2003&start_day=0 it displays correctly; with the 31 of December on Wednesday. I hope that is a little better. I will show my source below anyway; it is uncommentsd and not the neatest since this is just test code. <?php require_once 'includes/page_generation.php'; $pg =& new Page_Generation; $pg->start(); $cmonth = ''; $cyear = ''; $monthstring = ''; $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); if (array_key_exists('start_day', $_REQUEST) && !empty($_REQUEST['start_day'])) { $start_day = $_REQUEST['start_day']; } else { $start_day = 0; } $start_day = $start_day % 7; $months = array(); for ($month_count = 1; $month_count <= 12; $month_count++) { $months[strtolower(date('F', mktime(0,0,0,$month_count)))] = $month_count; } if (array_key_exists('month', $_REQUEST) && array_key_exists('year', $_REQUEST)) { if (is_numeric($_REQUEST['year']) && (is_numeric($_REQUEST['month']) || array_key_exists(strtolower($_REQUEST['month']), $months))) { define('CALENDAR_ENGINE', 'PearDate'); require_once 'Calendar/Month/Weekdays.php'; if (!is_numeric($_REQUEST['month'])) { $_REQUEST['month'] = $months[strtolower($_REQUEST['month'])]; } $Month =& new Calendar_Month_Weekdays($_REQUEST['year'], $_REQUEST['month'], $start_day); $Month->adjust(); $Month->build(); $cmonth = $Month->thisMonth(); $cyear = $Month->thisYear(); $monthstring = ucfirst(array_search($cmonth, $months)); echo $monthstring . " of " . $Month->thisYear()."<br /><br />\n"; echo "<table>\n"; echo "<thead>\n"; echo "<tr>\n"; $counter = 0; $daycount = $start_day; while ($counter < 7) { echo "<td>".$days[$daycount]."</td>\n"; $counter++; if ($daycount == 6) { $daycount = 0; } else { $daycount++; } } echo "</tr>\n"; echo "</thead>\n\n"; echo "<tbody>\n"; while ($Day = $Month->fetch()) { if ($Day->isFirst()) { echo "<tr>\n"; } if ($Day->isEmpty()) { echo "<td>&nbsp;</td>\n"; } else { echo '<td>'.$Day->thisDay()."</td>\n"; } if ($Day->isLast()) { echo "</tr>\n\n"; } } echo "</tbody>\n"; echo "</table>\n"; function translateMonth($month) { switch ($month) { case 1: return 'January'; case 2: return 'February'; case 3: return 'March'; case 4: return 'April'; case 5: return 'May'; case 6: return 'June'; case 7: return 'July'; case 8: return 'August'; case 9: return 'September'; case 10: return 'October'; case 11: return 'November'; case 12: return 'December'; } } echo "<br /><br />\n"; echo "<ul>\n"; echo "<li><a href=\"?month=".($cmonth+1)."&amp;year=$cyear&amp;start_day=$start_day\">Next Month</a></li>\n"; if ($cyear > 1 || ($cyear == 1 && $cmonth > 1)) { echo "<li>\n"; echo "<a href=\"?month=".($cmonth - 1)."&amp;year=$cyear&amp;start_day=$start_day\">Previous Month</a>\n"; echo "</li>\n"; } echo "<li>\n"; echo "<a href=\"?month=$cmonth&amp;year=".($cyear + 1)."&amp;start_day=$start_day\">Next Year</a>\n"; echo "</li>\n"; if ($cyear > 1) { echo "<li>\n"; echo "<a href=\"?month=$cmonth&amp;year=".($cyear - 1)."&amp;start_day=$start_day\">Previous Year</a>\n"; echo "</li>\n"; } echo "</ul>\n"; echo "<br /><br />\n"; echo "Start of the week is on a...\n"; echo "<ul>\n"; for ($i = 0; $i < 7; $i++) { echo "<li>\n"; if ($i != $start_day) { echo "<a href=\"?month=$cmonth&amp;year=$cyear&amp;start_day=$i\">\n"; } echo $days[$i]."\n"; if ($i != $start_day) { echo "</a>\n"; } echo "</li>\n"; } echo "</ul>\n"; echo "<br /><br />\n"; } } echo "<form method=\"post\">\n"; echo "Month: <input type=\"text\" name=\"month\" value=\"$monthstring\" />\n<br />\n"; echo "Year: <input type=\"text\" name=\"year\" value=\"$cyear\" />\n<br /><br />\n"; echo "Start of week: <select name=\"start_day\" size=\"7\">\n"; for ($i = 0; $i < 7; $i++) { echo "<option value=\"$i\""; if ($i == $start_day) { echo " selected=\"selected\""; } echo ">\n"; echo $days[$i]."\n"; echo "</option>\n"; } echo "</select>\n"; echo "</select>\n"; echo "<br />\n"; echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />\n"; echo "</form>\n"; echo "<br /><br />\n"; $pg->end(); echo $pg->getGenerationTime(); ?>

« previous php.pear.general (#12531) next »