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_Week extends Horde_Date_Repeater
 17: {
 18:     /**
 19:      * (7 * 24 * 60 * 60)
 20:      */
 21:     const WEEK_SECONDS = 604800;
 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:                 $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
 33:                 $sundayRepeater->now = $this->now;
 34:                 $nextSundaySpan = $sundayRepeater->next('future');
 35:                 $this->currentWeekStart = $nextSundaySpan->begin;
 36:                 break;
 37: 
 38:             case 'past':
 39:                 $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
 40:                 $sundayRepeater->now = clone $this->now;
 41:                 $sundayRepeater->now->day++;
 42:                 $sundayRepeater->next('past');
 43:                 $lastSundaySpan = $sundayRepeater->next('past');
 44:                 $this->currentWeekStart = $lastSundaySpan->begin;
 45:                 break;
 46:             }
 47:         } else {
 48:             $direction = ($pointer == 'future') ? 1 : -1;
 49:             $this->currentWeekStart->day += $direction * 7;
 50:         }
 51: 
 52:         return new Horde_Date_Span($this->currentWeekStart, $this->currentWeekStart->add(array('day' => 7)));
 53:     }
 54: 
 55:     public function this($pointer = 'future')
 56:     {
 57:         parent::this($pointer);
 58: 
 59:         switch ($pointer) {
 60:         case 'future':
 61:             $thisWeekStart = 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:             $thisSundaySpan = $sundayRepeater->this('future');
 65:             $thisWeekEnd = $thisSundaySpan->begin;
 66:             return new Horde_Date_Span($thisWeekStart, $thisWeekEnd);
 67: 
 68:         case 'past':
 69:             $thisWeekEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour));
 70:             $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
 71:             $sundayRepeater->now = $this->now;
 72:             $lastSundaySpan = $sundayRepeater->next('past');
 73:             $thisWeekStart = $lastSundaySpan->begin;
 74:             return new Horde_Date_Span($thisWeekStart, $thisWeekEnd);
 75: 
 76:         case 'none':
 77:             $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
 78:             $sundayRepeater->now = $this->now;
 79:             $lastSundaySpan = $sundayRepeater->next('past');
 80:             $thisWeekStart = $lastSundaySpan->begin;
 81:             $thisWeekEnd = clone $thisWeekStart;
 82:             $thisWeekEnd->day += 7;
 83:             return new Horde_Date_Span($thisWeekStart, $thisWeekEnd);
 84:         }
 85:     }
 86: 
 87:     public function offset($span, $amount, $pointer)
 88:     {
 89:         $direction = ($pointer == 'future') ? 1 : -1;
 90:         return $span->add(array('day' => $direction * $amount * 7));
 91:     }
 92: 
 93:     public function width()
 94:     {
 95:         return self::WEEK_SECONDS;
 96:     }
 97: 
 98:     public function __toString()
 99:     {
100:         return parent::__toString() . '-week';
101:     }
102: 
103: }
104: 
API documentation generated by ApiGen