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