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_MonthName extends Horde_Date_Repeater
 17: {
 18:     public $currentMonthStart;
 19:     public $type;
 20: 
 21:     public function __construct($type)
 22:     {
 23:         $this->type = $type;
 24:     }
 25: 
 26:     public function next($pointer = 'future')
 27:     {
 28:         parent::next($pointer);
 29: 
 30:         if (!$this->currentMonthStart) {
 31:             $targetMonth = $this->_monthNumber($this->type);
 32:             switch ($pointer) {
 33:             case 'future':
 34:                 if ($this->now->month < $targetMonth) {
 35:                     $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth, 'day' => 1));
 36:                 } else {
 37:                     $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth, 'day' => 1));
 38:                 }
 39:                 break;
 40: 
 41:             case 'none':
 42:                 if ($this->now->month <= $targetMonth) {
 43:                     $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth, 'day' => 1));
 44:                 } else {
 45:                     $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth, 'day' => 1));
 46:                 }
 47:                 break;
 48: 
 49:             case 'past':
 50:                 if ($this->now->month > $targetMonth) {
 51:                     $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth, 'day' => 1));
 52:                 } else {
 53:                     $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year - 1, 'month' => $targetMonth, 'day' => 1));
 54:                 }
 55:                 break;
 56:             }
 57:         } else {
 58:             switch ($pointer) {
 59:             case 'future':
 60:                 $this->currentMonthStart->year++;
 61:                 break;
 62: 
 63:             case 'past':
 64:                 $this->currentMonthStart->year--;
 65:                 break;
 66:             }
 67:         }
 68: 
 69:         return new Horde_Date_Span($this->currentMonthStart, $this->currentMonthStart->add(array('month' => 1)));
 70:     }
 71: 
 72:     public function this($pointer = 'future')
 73:     {
 74:         parent::this($pointer);
 75: 
 76:         switch ($pointer) {
 77:         case 'past':
 78:             return $this->next($pointer);
 79: 
 80:         case 'future':
 81:         case 'none':
 82:             return $this->next('none');
 83:         }
 84:     }
 85: 
 86:     public function width()
 87:     {
 88:         return Horde_Date_Repeater_Month::MONTH_SECONDS;
 89:     }
 90: 
 91:     public function index()
 92:     {
 93:         return $this->_monthNumber($this->type);
 94:     }
 95: 
 96:     public function __toString()
 97:     {
 98:         return parent::__toString() . '-monthname-' . $this->type;
 99:     }
100: 
101:     protected function _monthNumber($monthName)
102:     {
103:         $months = array(
104:             'january' => 1,
105:             'february' => 2,
106:             'march' => 3,
107:             'april' => 4,
108:             'may' => 5,
109:             'june' => 6,
110:             'july' => 7,
111:             'august' => 8,
112:             'september' => 9,
113:             'october' => 10,
114:             'november' => 11,
115:             'december' => 12,
116:         );
117:         if (!isset($months[$monthName])) {
118:             throw new InvalidArgumentException('Invalid month name "' . $monthName . '"');
119:         }
120:         return $months[$monthName];
121:     }
122: 
123: }
API documentation generated by ApiGen