Beispiel #1
0
function make_calendar($options = array())
{
    $months = arr_month();
    if (!empty($options['date'])) {
        $cal_date = string_time($options['date']);
    }
    if (empty($cal_date)) {
        $month = isset($months[$options['month']]) ? $options['month'] : date('n');
        $year = !empty($options['year']) ? $options['year'] : date('Y');
        $cal_date = strtotime($year . '-' . $month . '-01 00:00:00');
    } else {
        $month = date('n', $cal_date);
    }
    $start_day = !empty($options['start_day']) ? $options['start_day'] : 1;
    $weeks_to_show = !empty($options['weeks']) ? $options['weeks'] : null;
    $day_balance = date('N', $cal_date) - $start_day + 7;
    $day_balance %= 7;
    $cal_date = inc_date($cal_date, array('day' => -1 * $day_balance), 1);
    $today = strtotime(date('Y-m-d'));
    $n = 0;
    $calendar = array();
    $end_day = $start_day > 1 ? $start_day - 1 : 7;
    while (!$complete) {
        if (date('N', $cal_date) == $start_day) {
            $week = array();
        }
        $diff_month = date('n', $cal_date) != $month;
        $week[date('Y-m-d', $cal_date)] = array('diff' => $diff_month, 'today' => $cal_date == $today, 'content' => '<strong>' . date('j' . (($diff_month or !empty($weeks_to_show)) ? ' M' : ''), $cal_date) . '</strong>');
        if (date('N', $cal_date) == $end_day) {
            $calendar[] = $week;
        }
        $cal_date = inc_date($cal_date, array('day' => 1), 1);
        if ($n > 100 or empty($weeks_to_show) and date('n', $cal_date) != $month and date('N', $cal_date) == $start_day or !empty($weeks_to_show) and count($calendar) == $weeks_to_show) {
            $complete = true;
        }
        $n++;
    }
    return $calendar;
}
Beispiel #2
0
function month_limits($month, $year, $months = 1)
{
    if (empty($month)) {
        $month = date('n');
    }
    if (empty($year)) {
        $year = date('Y');
    }
    $cal_date = strtotime($year . '-' . $month . '-01 00:00:00');
    $limits['date_start'] = $cal_date = inc_date($cal_date, array('day' => -1 * (date('N', $cal_date) - 1)), 1);
    while (!$complete and $n < $months * 30 + 14) {
        $next_date = inc_date($cal_date, array('day' => 1), 1);
        $complete = (date('n', $next_date) == $month + $months and date('N', $next_date) == 1);
        if (empty($complete)) {
            $cal_date = $next_date;
        }
        $n++;
    }
    $limits['date_end'] = $cal_date;
    return $limits;
}