Ejemplo n.º 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;
}
Ejemplo n.º 2
0
function sql_date($date, &$error = null)
{
    if (empty($date)) {
        return false;
    }
    if (!is_numeric($date)) {
        $stamp = string_time($date, $error);
        if ($stamp === false) {
            return false;
        }
    } else {
        $stamp = $date;
    }
    $date = date('Y-m-d H:i:s', $stamp);
    return $date;
}