1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15:
16: class Horde_Date_Repeater_Hour extends Horde_Date_Repeater
17: {
18: public $currentHourStart;
19:
20: public function next($pointer = 'future')
21: {
22: parent::next($pointer);
23:
24: $direction = ($pointer == 'future') ? 1 : -1;
25: if (!$this->currentHourStart) {
26: $this->currentHourStart = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour));
27: }
28: $this->currentHourStart->hour += $direction;
29:
30: $end = clone $this->currentHourStart;
31: $end->hour++;
32: return new Horde_Date_Span($this->currentHourStart, $end);
33: }
34:
35: public function this($pointer = 'future')
36: {
37: parent::this($pointer);
38:
39: switch ($pointer) {
40: case 'future':
41: $hourStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min + 1));
42: $hourEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour + 1));
43: break;
44:
45: case 'past':
46: $hourStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour));
47: $hourEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
48: break;
49:
50: case 'none':
51: $hourStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour));
52: $hourEnd = $hourStart->add(array('hour' => 1));
53: break;
54: }
55:
56: return new Horde_Date_Span($hourStart, $hourEnd);
57: }
58:
59: public function offset($span, $amount, $pointer)
60: {
61: $direction = ($pointer == 'future') ? 1 : -1;
62: return $span->add(array('hour' => $direction * $amount));
63: }
64:
65: public function width()
66: {
67: return 3600;
68: }
69:
70: public function __toString()
71: {
72: return parent::__toString() . '-hour';
73: }
74:
75: }
76: