Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- setlocale(LC_ALL, array('Dutch_Netherlands', 'Dutch', 'nl_NL', 'nl', 'nl_NL.ISO8859-1', 'nld_NLD'));
- error_reporting(E_ALL);
- ini_set("display_errors", 1);
- class Calendar
- {
- public function getInfo($m, $y)
- {
- $days = date('t', mktime(0, 0, 0, $m, 1, $y));
- $firstday = date('N', strtotime('first day of ' . $y . '-' . $m));
- $info['days'] = $days;
- $info['firstday'] = $firstday;
- return $info;
- }
- public function makeMonth($m, $y)
- {
- $maand = array();
- // Get info for this year
- $info = $this->getInfo($m, $y);
- // Get array with dates
- $amount = $info['days'];
- for ($i = 1; $i <= $amount; $i++) {
- $maand[$i] = str_pad($i, 2, '0', STR_PAD_LEFT) . "-" . $m . "-" . $y;
- }
- // place the array content correctly
- $needed = 42;
- $begin = $info['firstday'] - 1;
- #begin van array
- for ($i = 0; $i < $begin; $i++) {
- array_unshift($maand, "Before Month Start");
- }
- #eind van array
- $nognodig = $needed - ($begin + $amount);
- for ($i = 0; $i < $nognodig; $i++) {
- array_push($maand, "After month");
- }
- return $maand;
- }
- public function buildArray()
- {
- //Build multidimensional array
- $calendar['calendar'] = array(
- $info = $this->getInfo(date("m", strtotime("-2 Months")), date("Y", strtotime("-2 Months"))),
- $maand = $this->makeMonth(date("m", strtotime("-2 Months")), date("Y", strtotime("-2 Months"))),
- $info = $this->getInfo(date("m", strtotime("-1 Months")), date("Y", strtotime("-1 Months"))),
- $maand = $this->makeMonth(date("m", strtotime("-1 Months")), date("Y", strtotime("-1 Months"))),
- $info = $this->getInfo(strftime('%m'), strftime('%Y')),
- $maand = $this->makeMonth(strftime('%m'), strftime('%Y')),
- $info = $this->getInfo(date("m", strtotime("+1 Months")), date("Y", strtotime("+1 Months"))),
- $maand = $this->makeMonth(date("m", strtotime("+1 Months")), date("Y", strtotime("+1 Months"))),
- $info = $this->getInfo(date("m", strtotime("+2 Months")), date("Y", strtotime("+2 Months"))),
- $maand = $this->makeMonth(date("m", strtotime("+2 Months")), date("Y", strtotime("+2 Months"))),
- $info = $this->getInfo(date("m", strtotime("+3 Months")), date("Y", strtotime("+3 Months"))),
- $maand = $this->makeMonth(date("m", strtotime("+3 Months")), date("Y", strtotime("+3 Months")))
- );
- echo '<pre>';
- print_r($calendar);
- echo '</pre>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement