public function testNextPast() { $mondays = new Horde_Date_Repeater_DayName('monday'); $mondays->now = $this->now; $span = $mondays->next('past'); $this->assertEquals('2006-08-14', $span->begin->format('Y-m-d')); $this->assertEquals('2006-08-15', $span->end->format('Y-m-d')); $span = $mondays->next('past'); $this->assertEquals('2006-08-07', $span->begin->format('Y-m-d')); $this->assertEquals('2006-08-08', $span->end->format('Y-m-d')); }
public function this($pointer = 'future') { parent::this($pointer); switch ($pointer) { case 'future': $thisWeekStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour + 1)); $sundayRepeater = new Horde_Date_Repeater_DayName('sunday'); $sundayRepeater->now = $this->now; $thisSundaySpan = $sundayRepeater->this('future'); $thisWeekEnd = $thisSundaySpan->begin; return new Horde_Date_Span($thisWeekStart, $thisWeekEnd); case 'past': $thisWeekEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour)); $sundayRepeater = new Horde_Date_Repeater_DayName('sunday'); $sundayRepeater->now = $this->now; $lastSundaySpan = $sundayRepeater->next('past'); $thisWeekStart = $lastSundaySpan->begin; return new Horde_Date_Span($thisWeekStart, $thisWeekEnd); case 'none': $sundayRepeater = new Horde_Date_Repeater_DayName('sunday'); $sundayRepeater->now = $this->now; $lastSundaySpan = $sundayRepeater->next('past'); $thisWeekStart = $lastSundaySpan->begin; $thisWeekEnd = clone $thisWeekStart; $thisWeekEnd->day += 7; return new Horde_Date_Span($thisWeekStart, $thisWeekEnd); } }
public function next($pointer = 'future') { parent::next($pointer); if (!$this->currentWeekStart) { switch ($pointer) { case 'future': $saturdayRepeater = new Horde_Date_Repeater_DayName('saturday'); $saturdayRepeater->now = $this->now; $nextSaturdaySpan = $saturdayRepeater->next('future'); $this->currentWeekStart = $nextSaturdaySpan->begin; break; case 'past': $saturdayRepeater = new Horde_Date_Repeater_DayName('saturday'); $saturdayRepeater->now = $this->now; $saturdayRepeater->now->day++; $lastSaturdaySpan = $saturdayRepeater->next('past'); $this->currentWeekStart = $lastSaturdaySpan->begin; break; } } else { $direction = $pointer == 'future' ? 1 : -1; $this->currentWeekStart->day += $direction * 7; } return new Horde_Date_Span($this->currentWeekStart, $this->currentWeekStart->add(array('day' => 2))); }