case 'past':
$hourStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour));
- $hourEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour + 1, 'min' => $this->now->min));
+ $hourEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
break;
case 'none':
$hourStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour));
- $hourEnd = clone($hourStart);
- $hourEnd->hour++;
+ $hourEnd = $hourStart->add(array('hour' => 1));
break;
}
$targetMonth = $this->_monthNumber($this->type);
switch ($pointer) {
case 'future':
- if ($this->now->month > $targetMonth) {
- $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth));
+ if ($this->now->month < $targetMonth) {
+ $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth, 'day' => 1));
} else {
- $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth));
+ $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth, 'day' => 1));
}
break;
case 'none':
if ($this->now->month <= $targetMonth) {
- $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth));
+ $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth, 'day' => 1));
} else {
- $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth));
+ $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth, 'day' => 1));
}
break;
case 'past':
if ($this->now->month > $targetMonth) {
- $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth));
+ $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth, 'day' => 1));
} else {
- $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year - 1, 'month' => $targetMonth));
+ $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year - 1, 'month' => $targetMonth, 'day' => 1));
}
break;
}
}
}
- return new Horde_Date_Span($this->currentMonthStart, new Horde_Date(array('year' => $this->currentMonthStart->year, 'month' => $this->currentMonthStart->month + 1)));
+ return new Horde_Date_Span($this->currentMonthStart, $this->currentMonthStart->add(array('month' => 1)));
}
public function this($pointer = 'future')
if ($pointer == 'future') {
if ($this->type->ambiguous) {
- foreach (array($midnight + $this->type, $midnight + $halfDay + $this->type, $tomorrowMidnight + $this->type) as $t) {
- if ($t >= $this->now) {
+ foreach (array($midnight->add($this->type->time), $midnight->add($halfDay + $this->type->time), $tomorrowMidnight->add($this->type->time)) as $t) {
+ if ($t->compareDateTime($this->now) >= 0) {
$this->currentTime = $t;
break;
}
}
} else {
- foreach (array($midnight + $this->type, $tomorrowMidnight + $this->type) as $t) {
- if ($t >= $this->now) {
+ foreach (array($midnight->add($this->type->time), $tomorrowMidnight->add($this->type->time)) as $t) {
+ if ($t->compareDateTime($this->now) >= 0) {
$this->currentTime = $t;
break;
}
}
}
- } else {
+ } elseif ($pointer == 'past') {
if ($this->type->ambiguous) {
- foreach (array($midnight + $halfDay + $this->type, $midnight + $this->type, $yesterdayMidnight + $this->type * 2) as $t) {
- if ($t <= $this->now) {
+ foreach (array($midnight->add($halfDay + $this->type->time), $midnight->add($this->type->time), $yesterdayMidnight->add($this->type->time * 2)) as $t) {
+ if ($t->compareDateTime($this->now) <= 0) {
$this->currentTime = $t;
break;
}
}
} else {
- foreach (array($midnight + $this->type, $yesterdayMidnight + $this->type) as $t) {
- if ($t <= $this->now) {
+ foreach (array($midnight->add($this->type->time), $yesterdayMidnight->add($this->type->time)) as $t) {
+ if ($t->compareDateTime($this->now) <= 0) {
$this->currentTime = $t;
break;
}
}
if (!$first) {
- $increment = $this->type->ambiguous ? $halfday : $fullDay;
- $this->currentTime += ($pointer == 'future') ? $increment : -$increment;
+ $increment = $this->type->ambiguous ? $halfDay : $fullDay;
+ $this->currentTime->sec += ($pointer == 'future') ? $increment : -$increment;
}
- return new Horde_Date_Span($this->currentTime, $this->currentTime + $this->width());
+ return new Horde_Date_Span($this->currentTime, $this->currentTime->add(1));
}
public function this($context = 'future')
return new Horde_Date_Tick($this->time * $other, $this->ambiguous);
}
- /*
- def to_f
- @time.to_f
- end
- */
-
public function __toString()
{
return $this->time . ($this->ambiguous ? '?' : '');
if (!$this->currentWeekStart) {
switch ($pointer) {
case 'future':
- $sundayRepeater = new Horde_Date_Repeater_DayName(Horde_Date::DATE_SUNDAY);
+ $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
$sundayRepeater->now = $this->now;
$nextSundaySpan = $sundayRepeater->next('future');
$this->currentWeekStart = $nextSundaySpan->begin;
break;
case 'past':
- $sundayRepeater = new Horde_Date_Repeater_DayName(Horde_Date::DATE_SUNDAY);
+ $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
$sundayRepeater->now = clone($this->now);
$sundayRepeater->now->day++;
$sundayRepeater->next('past');
$lastSundaySpan = $sundayRepeater->next('past');
- $currentWeekStart = $lastSundaySpan->begin;
+ $this->currentWeekStart = $lastSundaySpan->begin;
break;
}
} else {
$this->currentWeekStart->day += $direction * 7;
}
- $end = clone($this->currentWeekStart);
- $end->day += 7;
- return new Horde_Date_Span($this->currentWeekStart, $end);
+ return new Horde_Date_Span($this->currentWeekStart, $this->currentWeekStart->add(array('day' => 7)));
}
public function this($pointer = 'future')
switch ($pointer) {
case 'future':
- $thisWeekStart = new Horde_Date(array('year' => $now->year, 'month' => $now->month, 'day' => $now->day, 'hour' => $now->hour + 1));
- $sundayRepeater = new Horde_Date_Repeater_DayName(Horde_Date::DATE_SUNDAY);
+ $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' => $now->year, 'month' => $now->month, 'day' => $now->day, 'hour' => $now->hour));
- $sundayRepeater = new Horde_Date_Repeater_DayName(Horde_Date::DATE_SUNDAY);
+ $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(Horde_Date::DATE_SUNDAY);
+ $sundayRepeater = new Horde_Date_Repeater_DayName('sunday');
$sundayRepeater->now = $this->now;
$lastSundaySpan = $sundayRepeater->next('past');
$thisWeekStart = $lastSundaySpan->begin;
{
parent::next($pointer);
- if ($this->currentWeekStart) {
+ if (!$this->currentWeekStart) {
switch ($pointer) {
case 'future':
- $saturdayRepeater = new Horde_Date_Repeater_DayName(Horde_Date::DATE_SATURDAY);
+ $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(Horde_Date::DATE_SATURDAY);
+ $saturdayRepeater = new Horde_Date_Repeater_DayName('saturday');
$saturdayRepeater->now = $this->now;
$saturdayRepeater->now->day++;
$lastSaturdaySpan = $saturdayRepeater->next('past');
$this->currentWeekStart->day += $direction * 7;
}
- $currentWeekEnd = clone($this->currentWeekStart);
- $currentWeekEnd->day += 2;
- return new Horde_Date_Span($this->currentWeekStart, $currentWeekEnd);
+ return new Horde_Date_Span($this->currentWeekStart, $this->currentWeekStart->add(array('day' => 2)));
}
public function this($pointer = 'future')
switch ($pointer) {
case 'future':
case 'none':
- $saturdayRepeater = new Horde_Date_Repeater_DayName(Horde_Date::DATE_SATURDAY);
+ $saturdayRepeater = new Horde_Date_Repeater_DayName('saturday');
$saturdayRepeater->now = $this->now;
$thisSaturdaySpan = $saturdayRepeater->this('future');
- $thisSaturdaySpanEnd = $thisSaturdaySpan->begin;
- $thisSaturdaySpanEnd->day += 2;
- return new Horde_Date_Span($thisSaturdaySpan->begin, $thisSaturdaySpanEnd);
+ return new Horde_Date_Span($thisSaturdaySpan->begin, $thisSaturdaySpan->begin->add(array('day' => 2)));
case 'past':
- $saturdayRepeater = new Horde_Date_Repeater_DayName(Horde_Date::DATE_SATURDAY);
+ $saturdayRepeater = new Horde_Date_Repeater_DayName('saturday');
$saturdayRepeater->now = $this->now;
$lastSaturdaySpan = $saturdayRepeater->this('past');
- $lastSaturdaySpanEnd = $lastSaturdaySpan->begin;
- $lastSaturdaySpanEnd->day += 2;
- return new Horde_Date_Span($lastSaturdaySpan->begin, $lastSaturdaySpanEnd);
+ return new Horde_Date_Span($lastSaturdaySpan->begin, $lastSaturdaySpan->begin->add(array('day' => 2)));
}
}
public function offset($span, $amount, $pointer)
{
$direction = ($pointer == 'future') ? 1 : -1;
- $weekend = new Horde_Date_Repeater_Weekend('weekend');
- $weekend->now = $span->begin;
+ $weekend = new self();
+ $weekend->now = clone($span->begin);
$start = $weekend->next($pointer)->begin;
$start->day += ($amount - 1) * $direction * 7;
- // @FIXME
- return new Horde_Date_Span($start, $start + ($span->end - $span->begin));
+ return new Horde_Date_Span($start, $start->add($span->width()));
}
public function width()
parent::next($pointer);
if (!$this->currentYearStart) {
- switch ($pointer) {
- case 'future':
- $this->currentYearStart = new Horde_Date(array('year' => $this->now->year + 1));
- break;
-
- case 'past':
- $this->currentYearStart = new Horde_Date(array('year' => $this->now->year - 1));
- break;
- }
- } else {
- $diff = ($pointer == 'future') ? 1 : -1;
- $this->currentYearStart->year += $diff;
+ $this->currentYearStart = new Horde_Date(array('year' => $this->now->year, 'month' => 1, 'day' => 1));
}
- return new Horde_Date_Span($this->currentYearStart, new Horde_Date(array('year' => $this->currentYearStart->year + 1)));
+ $diff = ($pointer == 'future') ? 1 : -1;
+ $this->currentYearStart->year += $diff;
+
+ return new Horde_Date_Span($this->currentYearStart, $this->currentYearStart->add(array('year' => 1)));
}
public function this($pointer = 'future')
switch ($pointer) {
case 'future':
$thisYearStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day + 1));
- $thisYearEnd = new Horde_Date(array('year' => $this->now->year + 1));
+ $thisYearEnd = new Horde_Date(array('year' => $this->now->year + 1, 'month' => 1, 'day' => 1));
break;
case 'past':
- $thisYearStart = new Horde_Date(array('year' => $this->now->year));
+ $thisYearStart = new Horde_Date(array('year' => $this->now->year, 'month' => 1, 'day' => 1));
$thisYearEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day));
break;
case 'none':
- $thisYearStart = new Horde_Date(array('year' => $this->now->year));
- $thisYearEnd = new Horde_Date(array('year' => $this->now->year + 1));
+ $thisYearStart = new Horde_Date(array('year' => $this->now->year, 'month' => 1, 'day' => 1));
+ $thisYearEnd = new Horde_Date(array('year' => $this->now->year + 1, 'month' => 1, 'day' => 1));
break;
}
public function offset($span, $amount, $pointer)
{
$direction = ($pointer == 'future') ? 1 : -1;
-
- $sb = clone($span->begin);
- $sb->year += ($amount * $direction);
-
- $se = clone($span->end);
- $se->year += ($amount * $direction);
-
- return new Horde_Date_Span($se, $sb);
+ return $span->add(array('year' => ($amount * $direction)));
}
public function width()
*/
public function width()
{
- return $this->end->timestamp() - $this->begin->timestamp();
+ return abs($this->end->timestamp() - $this->begin->timestamp());
}
/**
$hours = new Horde_Date_Repeater_Hour();
$offsetSpan = $hours->offset($span, 3, 'future');
- $this->assertEquals('2006-08-16 16:00:00', (string)$offsetSpan->begin);
- $this->assertEquals('2006-08-16 17:00:00', (string)$offsetSpan->end);
+ $this->assertEquals('2006-08-16 17:00:00', (string)$offsetSpan->begin);
+ $this->assertEquals('2006-08-16 17:00:01', (string)$offsetSpan->end);
$offsetSpan = $hours->offset($span, 24, 'past');
$this->assertEquals('2006-08-15 14:00:00', (string)$offsetSpan->begin);
$t = new Horde_Date_Repeater_Time('4:00');
$t->now = $this->now;
- $this->assertEquals('2006-08-16 16:00:00', $t->next('future')->begin);
- $this->assertEquals('2006-08-17 04:00:00', $t->next('future')->begin);
+ $this->assertEquals('2006-08-16 16:00:00', (string)$t->next('future')->begin);
+ $this->assertEquals('2006-08-17 04:00:00', (string)$t->next('future')->begin);
$t = new Horde_Date_Repeater_Time('13:00');
$t->now = $this->now;
- $this->assertEquals('2006-08-17 13:00:00', $t->next('future')->begin);
- $this->assertEquals('2006-08-18 13:00:00', $t->next('future')->begin);
+ $this->assertEquals('2006-08-17 13:00:00', (string)$t->next('future')->begin);
+ $this->assertEquals('2006-08-18 13:00:00', (string)$t->next('future')->begin);
$t = new Horde_Date_Repeater_Time('0400');
$t->now = $this->now;
- $this->assertEquals('2006-08-17 04:00:00', $t->next('future')->begin);
- $this->assertEquals('2006-08-18 04:00:00', $t->next('future')->begin);
+ $this->assertEquals('2006-08-17 04:00:00', (string)$t->next('future')->begin);
+ $this->assertEquals('2006-08-18 04:00:00', (string)$t->next('future')->begin);
}
public function testNextPast()
{
$t = new Horde_Date_Repeater_Time('4:00');
$t->now = $this->now;
-
- $this->assertEquals('2006-08-16 04:00:00', $t->next('past')->begin);
- $this->assertEquals('2006-08-15 16:00:00', $t->next('past')->begin);
+ $this->assertEquals('2006-08-16 04:00:00', (string)$t->next('past')->begin);
+ $this->assertEquals('2006-08-15 16:00:00', (string)$t->next('past')->begin);
$t = new Horde_Date_Repeater_Time('13:00');
$t->now = $this->now;
-
- $this->assertEquals('2006-08-16 13:00:00', $t->next('past')->begin);
- $this->assertEquals('2006-08-15 13:00:00', $t->next('past')->begin);
+ $this->assertEquals('2006-08-16 13:00:00', (string)$t->next('past')->begin);
+ $this->assertEquals('2006-08-15 13:00:00', (string)$t->next('past')->begin);
}
public function testType()
$this->assertEquals('2005-01-01', $lastYear->begin->format('Y-m-d'));
$this->assertEquals('2006-01-01', $lastYear->end->format('Y-m-d'));
- $lastLastYear = $years->last('future');
+ $lastLastYear = $years->next('past');
$this->assertEquals('2004-01-01', $lastLastYear->begin->format('Y-m-d'));
$this->assertEquals('2005-01-01', $lastLastYear->end->format('Y-m-d'));
}