1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15:
16: class Horde_Date_Repeater_DayName extends Horde_Date_Repeater
17: {
18:
19: const DAY_SECONDS = 86400;
20:
21: public $currentDayStart;
22: public $type;
23:
24: public function __construct($type)
25: {
26: $this->type = $type;
27: }
28:
29: public function next($pointer = 'future')
30: {
31: parent::next($pointer);
32:
33: $direction = ($pointer == 'future') ? 1 : -1;
34:
35: if (!$this->currentDayStart) {
36: $this->currentDayStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day + $direction));
37:
38: $dayNum = $this->_dayNumber($this->type);
39: while ($this->currentDayStart->dayOfWeek() != $dayNum) {
40: $this->currentDayStart->day += $direction;
41: }
42: } else {
43: $this->currentDayStart->day += $direction * 7;
44: }
45:
46: $end = clone $this->currentDayStart;
47: $end->day++;
48: return new Horde_Date_Span($this->currentDayStart, $end);
49: }
50:
51: public function this($pointer = 'future')
52: {
53: parent::next($pointer);
54:
55: if ($pointer == 'none') {
56: $pointer = 'future';
57: }
58: return $this->next($pointer);
59: }
60:
61: public function width()
62: {
63: return self::DAY_SECONDS;
64: }
65:
66: public function __toString()
67: {
68: return parent::__toString() . '-dayname-' . $this->type;
69: }
70:
71: protected function _dayNumber($dayName)
72: {
73: $days = array(
74: 'monday' => Horde_Date::DATE_MONDAY,
75: 'tuesday' => Horde_Date::DATE_TUESDAY,
76: 'wednesday' => Horde_Date::DATE_WEDNESDAY,
77: 'thursday' => Horde_Date::DATE_THURSDAY,
78: 'friday' => Horde_Date::DATE_FRIDAY,
79: 'saturday' => Horde_Date::DATE_SATURDAY,
80: 'sunday' => Horde_Date::DATE_SUNDAY,
81: );
82: if (!isset($days[$dayName])) {
83: throw new InvalidArgumentException('Invalid day name "' . $dayName . '"');
84: }
85: return $days[$dayName];
86: }
87:
88: }
89: