/**
* Return the next past or future Span for the time that this Repeater represents
* pointer - Symbol representing which temporal direction to fetch the next day
* must be either :past or :future
*/
public function next($pointer = 'future')
{
parent::next($pointer);
$halfDay = 3600 * 12;
$fullDay = 3600 * 24;
$first = false;
if (!$this->currentTime) {
$first = true;
$midnight = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day));
$yesterdayMidnight = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day - 1));
$tomorrowMidnight = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day + 1));
if ($pointer == 'future') {
if ($this->ambiguous) {
foreach (array($midnight->add($this->type), $midnight->add($halfDay + $this->type), $tomorrowMidnight->add($this->type)) as $t) {
if ($t->compareDateTime($this->now) >= 0) {
$this->currentTime = $t;
break;
}
}
} else {
foreach (array($midnight->add($this->type), $tomorrowMidnight->add($this->type)) as $t) {
if ($t->compareDateTime($this->now) >= 0) {
$this->currentTime = $t;
break;
}
}
}
} elseif ($pointer == 'past') {
if ($this->ambiguous) {
foreach (array($midnight->add($halfDay + $this->type), $midnight->add($this->type), $yesterdayMidnight->add($this->type * 2)) as $t) {
if ($t->compareDateTime($this->now) <= 0) {
$this->currentTime = $t;
break;
}
}
} else {
foreach (array($midnight->add($this->type), $yesterdayMidnight->add($this->type)) as $t) {
if ($t->compareDateTime($this->now) <= 0) {
$this->currentTime = $t;
break;
}
}
}
}
if (!$this->currentTime) {
throw new Horde_Date_Repeater_Exception('Current time cannot be null at this point');
}
}
if (!$first) {
$increment = $this->ambiguous ? $halfDay : $fullDay;
$this->currentTime->sec += $pointer == 'future' ? $increment : -$increment;
}
return new Horde_Date_Span($this->currentTime, $this->currentTime->add(1));
}