<?php
require_once("Calendar/Month/Weekdays.php");
require_once("Date/Holidays.php");
$current_year = date("Y");
$current_month = date("n");
$calMonth = new Calendar_Month_Weekdays($current_year, $current_month, 0);//第3引数の0は週の最初を日曜に
$calMonth->build();
$ja = "data/Date_Holidays_Japan/lang/Japan/ja_JP.xml";
$dh = &Date_Holidays::factory("Japan", $current_year, "ja_JP");
$dh->addTranslationFile($ja, "ja_JP");
$holidays = array();
//祝日の月日をキーに祝日名を配列に格納
foreach ($dh->getHolidays() as $value) {
$holidays[$value->getDate()->format("%m%d")] = $value->getTitle();
}
echo "<h2>".$current_year."年".$current_month."月"."</h2>\n";
echo "<table class=\"calendar\">\n";
echo "<thead>\n";
echo "<tr><th>日</th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th>土</th></tr>\n";
echo "</thead>\n";
echo "<tbody>\n";
while ($day = $calMonth->fetch()) {
if ($day->isFirst()) {
echo '<tr>';
}
if ($day->isEmpty()) {
echo "<td> </td>";
} else {
$date = sprintf("%02d",$day->thisMonth()).sprintf("%02d",$day->thisDay());
if (array_key_exists($date, $holidays)) {
echo "<td class=\"holiday\">";//祝日のとき
} else if ($day->isFirst()) {
echo "<td class=\"sun\">";//週の最初(日曜)のとき
} else if ($day->isLast()) {
echo "<td class=\"sat\">";//週の最後(土曜)のとき
} else {
echo "<td>";
}
echo "<span class=\"day\">".$day->thisDay()."</span>";
//祝日に該当する月日の場合、祝日名を出力
if (array_key_exists($date, $holidays)) {
echo "<span class=\"holiday\">".$holidays[$date]."</span>";
}
echo "</td>";
}
if ($day->isLast()) {
echo "</tr>\n";
}
}
echo "</tbody>\n";
echo "</table>\n";
?>