1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15:
16: class Horde_Date_Repeater_Week extends Horde_Date_Repeater
17: {
18: 19: 20:
21: const WEEK_SECONDS = 604800;
22:
23: public $currentWeekStart;
24:
25: public function next($pointer = 'future')
26: {
27: parent::next($pointer);
28:
29: if (!$this->currentWeekStart) {
30: switch ($pointer) {
31: case 'future':
32: $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
33: $sundayRepeater->now = $this->now;
34: $nextSundaySpan = $sundayRepeater->next('future');
35: $this->currentWeekStart = $nextSundaySpan->begin;
36: break;
37:
38: case 'past':
39: $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
40: $sundayRepeater->now = clone $this->now;
41: $sundayRepeater->now->day++;
42: $sundayRepeater->next('past');
43: $lastSundaySpan = $sundayRepeater->next('past');
44: $this->currentWeekStart = $lastSundaySpan->begin;
45: break;
46: }
47: } else {
48: $direction = ($pointer == 'future') ? 1 : -1;
49: $this->currentWeekStart->day += $direction * 7;
50: }
51:
52: return new Horde_Date_Span($this->currentWeekStart, $this->currentWeekStart->add(array('day' => 7)));
53: }
54:
55: public function this($pointer = 'future')
56: {
57: parent::this($pointer);
58:
59: switch ($pointer) {
60: case 'future':
61: $thisWeekStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour + 1));
62: $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
63: $sundayRepeater->now = $this->now;
64: $thisSundaySpan = $sundayRepeater->this('future');
65: $thisWeekEnd = $thisSundaySpan->begin;
66: return new Horde_Date_Span($thisWeekStart, $thisWeekEnd);
67:
68: case 'past':
69: $thisWeekEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour));
70: $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
71: $sundayRepeater->now = $this->now;
72: $lastSundaySpan = $sundayRepeater->next('past');
73: $thisWeekStart = $lastSundaySpan->begin;
74: return new Horde_Date_Span($thisWeekStart, $thisWeekEnd);
75:
76: case 'none':
77: $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
78: $sundayRepeater->now = $this->now;
79: $lastSundaySpan = $sundayRepeater->next('past');
80: $thisWeekStart = $lastSundaySpan->begin;
81: $thisWeekEnd = clone $thisWeekStart;
82: $thisWeekEnd->day += 7;
83: return new Horde_Date_Span($thisWeekStart, $thisWeekEnd);
84: }
85: }
86:
87: public function offset($span, $amount, $pointer)
88: {
89: $direction = ($pointer == 'future') ? 1 : -1;
90: return $span->add(array('day' => $direction * $amount * 7));
91: }
92:
93: public function width()
94: {
95: return self::WEEK_SECONDS;
96: }
97:
98: public function __toString()
99: {
100: return parent::__toString() . '-week';
101: }
102:
103: }
104: