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