Overview

Packages

  • Date

Classes

  • Horde_Date
  • Horde_Date_Exception
  • Horde_Date_Recurrence
  • Horde_Date_Repeater
  • Horde_Date_Repeater_Day
  • Horde_Date_Repeater_DayName
  • Horde_Date_Repeater_DayPortion
  • Horde_Date_Repeater_Fortnight
  • Horde_Date_Repeater_Hour
  • Horde_Date_Repeater_Minute
  • Horde_Date_Repeater_Month
  • Horde_Date_Repeater_MonthName
  • Horde_Date_Repeater_Season
  • Horde_Date_Repeater_SeasonName
  • Horde_Date_Repeater_Second
  • Horde_Date_Repeater_Time
  • Horde_Date_Repeater_Week
  • Horde_Date_Repeater_Weekend
  • Horde_Date_Repeater_Year
  • Horde_Date_Span
  • Horde_Date_Translation
  • Horde_Date_Utils

Exceptions

  • Horde_Date_Repeater_Exception
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
 4:  *
 5:  * See the enclosed file COPYING for license information (LGPL). If you
 6:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 7:  *
 8:  * @category Horde
 9:  * @package  Date
10:  */
11: 
12: /**
13:  * @category Horde
14:  * @package  Date
15:  */
16: class Horde_Date_Repeater_DayName extends Horde_Date_Repeater
17: {
18:     // (24 * 60 * 60)
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: 
API documentation generated by ApiGen