function create_calendar($month, $year, $week)
 {
     global $site_settings;
     $week_start = $this->cal['week_start'];
     /* make list of holidays for the given $year */
     $holidays = new US_Federal_Holidays($year, $site_settings['site_settings']['timezone']);
     // rewrite received holidays list into timestamp as the array key and name of holiday as the array's value
     $holiday_list = array();
     foreach ($holidays->get_list() as $v) {
         $holiday_list[$v['timestamp']] = $v['name'];
     }
     /* fill in day of week placeholder array with numbers for days of the week starting with $week_start */
     $index = sprintf('%4s-%02s-01', $year, $month);
     $this->cal['wks'][$index] = array();
     for ($i = 0; $i <= 6; $i++) {
         $this->cal['wkh'][$i] = $week_start;
         $week_start++;
         if (8 == $week_start) {
             $week_start = 1;
         }
     }
     /* Get day number 1...7 for the first day of the month */
     $date = new DateTime(sprintf('%s-%s-01', $year, $month));
     $dow_month_start = $date->format('N');
     // 'N' - ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
     /* Total number of days in month */
     $days_in_month = $date->format('t');
     /* Fill in calendar array $this->cal['wks'] with days of the month. $wks[<week number>][<placeholder>]. Day names are stored in $wkh for each placeholder as key */
     /* place array of needed values into each cell. Could be anything from a number for day of the month, to event names, times, etc. */
     $i = array_search($dow_month_start, $this->cal['wkh']);
     $j = 1;
     if ($i) {
         $this->cal['wks'][$index][$j] = array_fill(0, $i, FALSE);
     }
     for ($d = 1; $d <= $days_in_month; $d++) {
         $data = array('d' => $d, 'w' => $j + $week);
         // array of data to be placed into each calendar cell
         // check for holidays
         $timestamp = strtotime(sprintf('%u-%02u-%02u', $year, $month, $d));
         if (array_key_exists($timestamp, $holiday_list)) {
             $data['h'] = $holiday_list[$timestamp];
         }
         $this->cal['wks'][$index][$j][$i] = $data;
         $i++;
         if (7 == $i) {
             $i = 0;
             $j++;
         }
     }
     $k = $i;
     while ($k > 0 && $k <= 6) {
         $this->cal['wks'][$index][$j][$k] = FALSE;
         $k++;
     }
 }
Beispiel #2
0
    }
    private function set_list()
    {
        $this->list = array(array("name" => "New Year's Day", "timestamp" => $this->adjust_fixed_holiday(mktime(0, 0, 0, 1, 1, $this->year))), array("name" => "Birthday of Martin Luther King, Jr.", "timestamp" => strtotime("3 Mondays", mktime(0, 0, 0, 1, 1, $this->year))), array("name" => "Wasthington's Birthday", "timestamp" => strtotime("3 Mondays", mktime(0, 0, 0, 2, 1, $this->year))), array("name" => "Memorial Day ", "timestamp" => strtotime("last Monday of May {$this->year}")), array("name" => "Independence day ", "timestamp" => $this->adjust_fixed_holiday(mktime(0, 0, 0, 7, 4, $this->year))), array("name" => "Labor Day ", "timestamp" => strtotime("first Monday of September {$this->year}")), array("name" => "Columbus Day ", "timestamp" => strtotime("2 Mondays", mktime(0, 0, 0, 10, 1, $this->year))), array("name" => "Veteran's Day ", "timestamp" => $this->adjust_fixed_holiday(mktime(0, 0, 0, 11, 11, $this->year))), array("name" => "Thanksgiving Day ", "timestamp" => strtotime("4 Thursdays", mktime(0, 0, 0, 11, 1, $this->year))), array("name" => "Christmas ", "timestamp" => $this->adjust_fixed_holiday(mktime(0, 0, 0, 12, 25, $this->year))));
    }
    public function get_list()
    {
        return $this->list;
    }
    public function is_holiday($timestamp)
    {
        foreach ($this->list as $holiday) {
            if ($timestamp == $holiday["timestamp"]) {
                return true;
            }
        }
        return false;
    }
}
$holidays = new US_Federal_Holidays();
echo "<table border=\"1\">";
foreach ($holidays->get_list() as $holiday) {
    echo "<tr>";
    echo "<td>" . $holiday["name"] . "</td>";
    echo "<td>" . date("F j, Y", $holiday["timestamp"]) . "</td>";
    echo "</tr>";
}
echo "<tr><td colspan='2' bgcolor='#ccc'>";
echo "Today (" . date("F j, Y") . ") is " . ($holidays->is_holiday(time()) ? "" : "not ") . "a holiday.";
echo "</td></tr>";
echo "</table>";