I'm creating a calendar script for our intranet, built basically off a series of included files.
I can handle almost every holiday in this fashion, except, of course, easter?
Any clues? Or am I best off defining in a static file the dates of easter for the next 10 years or so, and then including that file?
EDIT: solved, using easter_date()
<?php include ('global/inc/calendar'.date("m").'.inc.php\'); ?><?php
$firstday = date("w", mktime(0,0,0,date("n"), 1, date("Y")));
$holidays = array();
// New Year's Day
if (date("w", mktime(0,0,0, 1, 1, date("Y"))) == 0) {
// if NYD is a Sunday
$holidays[2] = "New Year's Day Public Holiday";
} elseif (date("w", mktime(0,0,0, 1, 1, date("Y"))) == 6) {
// if it's a Sat
$holidays[3] = "New Year's Day Public Holiday";
} else {
// any other day
$holidays[1] = "New Year's Day";
}
// Australia Day
if (date("w", mktime(0,0,0, 1, 26, date("Y"))) == 0) {
// if the 26th is a Sunday.
$holidays[27] = "Anzac Day Public Holiday";
} elseif (date("w", mktime(0,0,0, 1, 26, date("Y"))) == 6) {
// if it's a Sat
$holidays[28] = "Anzac Day Public Holiday";
} else {
// any other day
$holidays[26] = "Anzac Day";
}
print (" <table style=\"width: 100%;\">
<tbody>");
// find the day on which the first day of the month falls
switch ($firstday) {
case "0":
// the first is a Sunday
print ("<tr>\n");
break;
case "1":
// the first is a Monday
print ("<tr>\n<td> </td>\n");
break;
case "2":
// the first is a Tuesday
print ("<tr>\n<td> </td>\n<td> </td> \n");
break;
case "3":
// the first is a Wednesday
print ("<tr>\n<td> </td>\n<td> </td> \n<td> </td>\n");
break;
case "4":
// the first is a Thursday
print ("<tr>\n<td> </td>\n<td> </td> \n<td> </td>\n<td> </td>\n");
break;
case "5":
// the first is a Friday
print ("<tr>\n<td> </td>\n<td> </td> \n<td> </td>\n<td> </td>\n<td> </td>\n");
break;
case "6":
// the first is a Saturday
print ("<tr>\n <td> </td>\n<td> </t d>\n<td> </td>\n<td> </td>\n<t d> </td>\n<td> </td>\n");
break;
}
for ($d = 1; $d <= date("t"); $d++) {
// for all the days in a month, print a cell in the table
$style = " style=\"";
if (array_key_exists($d, $holidays)) {
$style .= "font-weight: 700; color: #CC0000;";
}
if ($d == date("j")) {
$style .= "background-color: #FFFFFF;";
}
$style .= "\"";
if (date("w", mktime(0,0,0,date("n"), $d, date("Y"))) == 0) {
print ("<tr>\n<td class='CalendarDay'".$style.">".$d."</td>\n");
} else if (date("w", mktime(0,0,0,date("n"), $d, date("Y"))) == 6) {
print ("<td class='CalendarDay'".$style.">".$d."</td>\n</tr>\n");
} else {
print ("<td class='CalendarDay'".$style.">".$d."</td>\n");
}
}
print (" </tbody>
</table>");
print ("<p style=\"font-weight: 700;\">Holidays this Month</p>\n
<table>
<tbody>");
foreach ($holidays as $key => $value) {
$M = date("M");
print ("<tr>
<td style=\"width: 25%;\">$M $key:</td><td>$value</td>
</tr>");
}
print (" </tbody>
</table>");
?>
I can handle almost every holiday in this fashion, except, of course, easter?
Any clues? Or am I best off defining in a static file the dates of easter for the next 10 years or so, and then including that file?
EDIT: solved, using easter_date()
