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