1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15:
16: class Horde_Date_Repeater_Weekend extends Horde_Date_Repeater
17: {
18: 19: 20:
21: const WEEKEND_SECONDS = 172800;
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: $saturdayRepeater = new Horde_Date_Repeater_DayName('saturday');
33: $saturdayRepeater->now = $this->now;
34: $nextSaturdaySpan = $saturdayRepeater->next('future');
35: $this->currentWeekStart = $nextSaturdaySpan->begin;
36: break;
37:
38: case 'past':
39: $saturdayRepeater = new Horde_Date_Repeater_DayName('saturday');
40: $saturdayRepeater->now = $this->now;
41: $saturdayRepeater->now->day++;
42: $lastSaturdaySpan = $saturdayRepeater->next('past');
43: $this->currentWeekStart = $lastSaturdaySpan->begin;
44: break;
45: }
46: } else {
47: $direction = ($pointer == 'future') ? 1 : -1;
48: $this->currentWeekStart->day += $direction * 7;
49: }
50:
51: return new Horde_Date_Span($this->currentWeekStart, $this->currentWeekStart->add(array('day' => 2)));
52: }
53:
54: public function this($pointer = 'future')
55: {
56: parent::this($pointer);
57:
58: switch ($pointer) {
59: case 'future':
60: case 'none':
61: $saturdayRepeater = new Horde_Date_Repeater_DayName('saturday');
62: $saturdayRepeater->now = $this->now;
63: $thisSaturdaySpan = $saturdayRepeater->this('future');
64: return new Horde_Date_Span($thisSaturdaySpan->begin, $thisSaturdaySpan->begin->add(array('day' => 2)));
65:
66: case 'past':
67: $saturdayRepeater = new Horde_Date_Repeater_DayName('saturday');
68: $saturdayRepeater->now = $this->now;
69: $lastSaturdaySpan = $saturdayRepeater->this('past');
70: return new Horde_Date_Span($lastSaturdaySpan->begin, $lastSaturdaySpan->begin->add(array('day' => 2)));
71: }
72: }
73:
74: public function offset($span, $amount, $pointer)
75: {
76: $direction = ($pointer == 'future') ? 1 : -1;
77: $weekend = new self();
78: $weekend->now = clone $span->begin;
79: $start = $weekend->next($pointer)->begin;
80: $start->day += ($amount - 1) * $direction * 7;
81: return new Horde_Date_Span($start, $start->add($span->width()));
82: }
83:
84: public function width()
85: {
86: return self::WEEKEND_SECONDS;
87: }
88:
89: public function __toString()
90: {
91: return parent::__toString() . '-weekend';
92: }
93:
94: }
95: