-class Chronic::RepeaterDay < Chronic::Repeater #:nodoc:
- DAY_SECONDS = 86_400 # (24 * 60 * 60)
-
- def next(pointer)
- super
-
- if !@current_day_start
- @current_day_start = Time.local(@now.year, @now.month, @now.day)
- end
-
- direction = pointer == :future ? 1 : -1
- @current_day_start += direction * DAY_SECONDS
-
- Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
- end
-
- def this(pointer = :future)
- super
-
- case pointer
- when :future
- day_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour + 1)
- day_end = Time.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
- when :past
- day_begin = Time.construct(@now.year, @now.month, @now.day)
- day_end = Time.construct(@now.year, @now.month, @now.day, @now.hour)
- when :none
- day_begin = Time.construct(@now.year, @now.month, @now.day)
- day_end = Time.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
- end
-
- Chronic::Span.new(day_begin, day_end)
- end
-
- def offset(span, amount, pointer)
- direction = pointer == :future ? 1 : -1
- span + direction * amount * DAY_SECONDS
- end
-
- def width
- DAY_SECONDS
- end
-
- def to_s
- super << '-day'
- end
-end
\ No newline at end of file
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Day extends Horde_Date_Parser_Locale_Base_Repeater
+{
+ // (24 * 60 * 60)
+ const DAY_SECONDS = 86400;
+
+ public $currentDayStart;
+
+ public function next($pointer)
+ {
+ parent::next($pointer);
+
+ if (!$this->currentDayStart) {
+ $this->currentDayStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day));
+ }
+
+ $direction = ($pointer == 'future') ? 1 : -1;
+ $this->currentDayStart->day += $direction;
+
+ $end = clone($this->currentDayStart);
+ $end->day += 1;
+
+ return new Horde_Date_Span($this->currentDayStart, $end);
+ }
+
+ public function this($pointer = 'future')
+ {
+ parent::this($pointer);
+
+ switch ($pointer) {
+ case 'future':
+ $dayBegin = new Horde_Date(array('year' => $now->year, 'month' => $now->month, 'day' => $now->day, 'hour' => $now->hour + 1));
+ $dayEnd = new Horde_Date(array('year' => $now->year, 'month' => $now->month, 'day' => $now->day + 1));
+ break;
+
+ case 'past':
+ $dayBegin = new Horde_Date(array('year' => $now->year, 'month' => $now->month, 'day' => $now->day));
+ $dayBegin = new Horde_Date(array('year' => $now->year, 'month' => $now->month, 'day' => $now->day, 'hour' => $now->hour));
+ break;
+
+ case 'none':
+ $dayBegin = new Horde_Date(array('year' => $now->year, 'month' => $now->month, 'day' => $now->day));
+ $dayEnd = new Horde_Date(array('year' => $now->year, 'month' => $now->month, 'day' => $now->day + 1));
+ break;
+ }
+
+ return new Horde_Date_Span($dayBegin, $dayEnd);
+ }
+
+ public function offset($span, $amount, $pointer)
+ {
+ $direction = ($pointer == 'future') ? 1 : -1;
+ return $span->add($direction * $amount * self::DAY_SECONDS);
+ }
+
+ public function width()
+ {
+ return self::DAY_SECONDS;
+ }
+
+ public function __toString()
+ {
+ return parent::__toString() . '-day';
+ }
+
+}
-class Chronic::RepeaterYear < Chronic::Repeater #:nodoc:
-
- def next(pointer)
- super
-
- if !@current_year_start
- case pointer
- when :future
- @current_year_start = Time.construct(@now.year + 1)
- when :past
- @current_year_start = Time.construct(@now.year - 1)
- end
- else
- diff = pointer == :future ? 1 : -1
- @current_year_start = Time.construct(@current_year_start.year + diff)
- end
-
- Chronic::Span.new(@current_year_start, Time.construct(@current_year_start.year + 1))
- end
-
- def this(pointer = :future)
- super
-
- case pointer
- when :future
- this_year_start = Time.construct(@now.year, @now.month, @now.day) + Chronic::RepeaterDay::DAY_SECONDS
- this_year_end = Time.construct(@now.year + 1, 1, 1)
- when :past
- this_year_start = Time.construct(@now.year, 1, 1)
- this_year_end = Time.construct(@now.year, @now.month, @now.day)
- when :none
- this_year_start = Time.construct(@now.year, 1, 1)
- this_year_end = Time.construct(@now.year + 1, 1, 1)
- end
-
- Chronic::Span.new(this_year_start, this_year_end)
- end
-
- def offset(span, amount, pointer)
- direction = pointer == :future ? 1 : -1
-
- sb = span.begin
- new_begin = Time.construct(sb.year + (amount * direction), sb.month, sb.day, sb.hour, sb.min, sb.sec)
-
- se = span.end
- new_end = Time.construct(se.year + (amount * direction), se.month, se.day, se.hour, se.min, se.sec)
-
- Chronic::Span.new(new_begin, new_end)
- end
-
- def width
- (365 * 24 * 60 * 60)
- end
-
- def to_s
- super << '-year'
- end
-end
\ No newline at end of file
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Year extends Horde_Date_Parser_Locale_Base_Repeater
+{
+ public $currentYearStart;
+
+ public function next($pointer)
+ {
+ 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;
+ }
+
+ return new Horde_Date_Span($this->currentYearStart, new Horde_Date(array('year' => $this->currentYearStart->year + 1)));
+ }
+
+ public function this($pointer = 'future')
+ {
+ parent::this($pointer);
+
+ 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));
+ break;
+
+ case 'past':
+ $thisYearStart = new Horde_Date(array('year' => $this->now->year));
+ $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));
+ break;
+ }
+
+ return new Horde_Date_Span($thisYearStart, $thisYearEnd);
+ }
+
+ 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);
+ }
+
+ public function width()
+ {
+ return (365 * 24 * 60 * 60);
+ }
+
+ public function __toString()
+ {
+ return parent::__toString() . '-year';
+ }
+
+}