3) ? '%A' : '%a'; $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); if (Calendar::$start_monday === TRUE) { array_push($days, array_shift($days)); } if (strpos(Kohana::config('locale.language.0'), 'en') !== 0) { foreach ($days as $i => $day) { $days[$i] = strftime($format, strtotime($day)); } } if (is_int($length) OR ctype_digit($length)) { foreach ($days as $i => $day) { $days[$i] = utf8::substr($day, 0, $length); } } return $days; } public static function factory($month = NULL, $year = NULL) { return new Calendar($month, $year); } public function __construct($month = NULL, $year = NULL) { empty($month) and $month = date('n'); empty($year) and $year = date('Y'); $this->month = (int) $month; $this->year = (int) $year; if (Calendar::$start_monday === TRUE) { $this->week_start = 1; } } public function __get($key) { if ($key === 'month' OR $key === 'year') { return $this->$key; } } public function event($name = NULL) { return new Calendar_Event($this); } public function standard($name) { switch ($name) { case 'today': $this->attach($this->event()->condition('timestamp', strtotime('today'))->add_class('today')); break; case 'prev-next': $this->attach($this->event()->condition('current', FALSE)->add_class('prev-next')); break; case 'holidays': $event = $this->event()->condition('current', TRUE)->add_class('holiday'); $holiday = clone $event; $this->attach($holiday->condition('month', 1)->condition('day', 1)); $holiday = clone $event; $this->attach($holiday->condition('month', 2)->condition('day', 14)); $holiday = clone $event; $this->attach($holiday->condition('month', 3)->condition('day', 17)); $holiday = clone $event; $this->attach($holiday->condition('easter', TRUE)); $holiday = clone $event; $this->attach($holiday->condition('month', 5)->condition('day_of_week', 1)->condition('last_occurrence', TRUE)); $holiday = clone $event; $this->attach($holiday->condition('month', 7)->condition('day', 4)); $holiday = clone $event; $this->attach($holiday->condition('month', 9)->condition('day_of_week', 1)->condition('occurrence', 1)); $holiday = clone $event; $this->attach($holiday->condition('month', 10)->condition('day', 31)); $holiday = clone $event; $this->attach($holiday->condition('month', 11)->condition('day_of_week', 4)->condition('occurrence', 4)); $holiday = clone $event; $this->attach($holiday->condition('month', 12)->condition('day', 25)); break; case 'weekends': $this->attach($this->event()->condition('weekend', TRUE)->add_class('weekend')); break; } return $this; } public function weeks() { $first = mktime(1, 0, 0, $this->month, 1, $this->year); $total = (int) date('t', $first); $last = mktime(1, 0, 0, $this->month, $total, $this->year); $month = $week = array(); $days = 0; $week_number = 1; if (($w = (int) date('w', $first) - $this->week_start) < 0) { $w = 6; } if ($w > 0) { $n = (int) date('t', mktime(1, 0, 0, $this->month - 1, 1, $this->year)); for ($i = $n - $w + 1, $t = $w; $t > 0; $t--, $i++) { $this->notify(array($this->month - 1, $i, $this->year, $week_number, FALSE)); $week[] = array($i, FALSE, $this->observed_data); $days++; } } for ($i = 1; $i <= $total; $i++) { if ($days % 7 === 0) { $month[] = $week; $week = array(); $week_number++; } $this->notify(array($this->month, $i, $this->year, $week_number, TRUE)); $week[] = array($i, TRUE, $this->observed_data); $days++; } if (($w = (int) date('w', $last) - $this->week_start) < 0) { $w = 6; } if ($w >= 0) { for ($i = 1, $t = 6 - $w; $t > 0; $t--, $i++) { $this->notify(array($this->month + 1, $i, $this->year, $week_number, FALSE)); $week[] = array($i, FALSE, $this->observed_data); } } if ( ! empty($week)) { $month[] = $week; } return $month; } public function add_data(array $data) { $this->observed_data['classes'] += $data['classes']; if ( ! empty($data['output'])) { $this->observed_data['output'][] = $data['output']; } } public function notify($data) { $this->observed_data = array ( 'classes' => array(), 'output' => array(), ); parent::notify($data); } public function render() { $view = new View('kohana_calendar', array ( 'month' => $this->month, 'year' => $this->year, 'weeks' => $this->weeks(), )); return $view->render(); } public function __toString() { return $this->render(); } }