1: <?php
2: 3: 4: 5: 6: 7:
8: class Kronolith_Day extends Horde_Date
9: {
10: 11: 12: 13: 14: 15:
16: public $slotsPerHour;
17:
18: 19: 20: 21: 22: 23:
24: public $slotsPerDay;
25:
26: 27: 28: 29: 30: 31:
32: public $slotLength;
33:
34: 35: 36: 37: 38:
39: public $slots = array();
40:
41: 42: 43: 44: 45: 46: 47:
48: public function __construct($month = null, $day = null, $year = null)
49: {
50: if (is_null($month)) {
51: $month = date('n');
52: }
53: if (is_null($year)) {
54: $year = date('Y');
55: }
56: if (is_null($day)) {
57: $day = date('j');
58: }
59: parent::__construct(array('year' => $year, 'month' => $month, 'mday' => $day));
60:
61: $this->slotsPerHour = $GLOBALS['prefs']->getValue('slots_per_hour');
62: if (!$this->slotsPerHour) {
63: $this->slotsPerHour = 1;
64: }
65: $this->slotsPerDay = $this->slotsPerHour * 24;
66: $this->slotLength = 60 / $this->slotsPerHour;
67:
68: for ($i = 0; $i < $this->slotsPerDay; $i++) {
69: $minutes = $i * $this->slotLength;
70: $this->slots[$i]['hour'] = (int)($minutes / 60);
71: $this->slots[$i]['min'] = $minutes % 60;
72: }
73: }
74:
75: public function getTime($format, $offset = 0)
76: {
77: $date = new Horde_Date(array('month' => $this->month,
78: 'mday' => $this->mday + $offset,
79: 'year' => $this->year));
80: return $date->strftime($format);
81: }
82:
83: public function getTomorrow()
84: {
85: $date = new Horde_Date(array('month' => $this->month,
86: 'mday' => $this->mday + 1,
87: 'year' => $this->year));
88: return $date;
89: }
90:
91: public function getYesterday()
92: {
93: $date = new Horde_Date(array('month' => $this->month,
94: 'mday' => $this->mday - 1,
95: 'year' => $this->year));
96: return $date;
97: }
98:
99: public function isToday()
100: {
101: return $this->compareDate(new Horde_Date(mktime(0, 0, 0))) == 0;
102: }
103:
104: public function isTomorrow()
105: {
106: $date = new Horde_Date(array('month' => $this->month,
107: 'mday' => $this->mday - 1,
108: 'year' => $this->year));
109: return $date->compareDate(new Horde_Date(mktime(0, 0, 0))) == 0;
110: }
111:
112: public function diff()
113: {
114: $day2 = new Kronolith_Day();
115: return Date_Calc::dateDiff($this->mday, $this->month, $this->year,
116: $day2->mday, $day2->month, $day2->year);
117: }
118:
119: }
120: