<?php
class Horde_Date_Parser_Locale_Base_Repeater_Hour extends Horde_Date_Parser_Locale_Base_Repeater
{
- /**
- * 60 * 60
- */
- const HOUR_SECONDS = 3600;
-
- def next(pointer)
- super
-
- if !@current_hour_start
- case pointer
- when :future
- @current_hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour + 1)
- when :past
- @current_hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour - 1)
- end
- else
- direction = pointer == :future ? 1 : -1
- @current_hour_start += direction * HOUR_SECONDS
- end
-
- Chronic::Span.new(@current_hour_start, @current_hour_start + HOUR_SECONDS)
- end
-
- def this(pointer = :future)
- super
-
- case pointer
- when :future
- hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
- hour_end = Time.construct(@now.year, @now.month, @now.day, @now.hour + 1)
- when :past
- hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour)
- hour_end = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
- when :none
- hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour)
- hour_end = hour_begin + HOUR_SECONDS
- end
-
- Chronic::Span.new(hour_start, hour_end)
- end
-
- def offset(span, amount, pointer)
- direction = pointer == :future ? 1 : -1
- span + direction * amount * HOUR_SECONDS
- end
-
- def width
- HOUR_SECONDS
- end
-
- def to_s
- super << '-hour'
- end
-end
\ No newline at end of file
+ public $currentHourStart;
+
+ public function next($pointer)
+ {
+ parent::next($pointer);
+
+ $direction = ($pointer == 'future') ? 1 : -1;
+ if (!$this->currentHourStart) {
+ $this->currentHourStart = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour));
+ }
+ $this->currentHourStart->hour += $direction;
+
+ $end = clone($this->currentHourStart);
+ $end->hour++;
+ return new Horde_Date_Span($this->currentHourStart, $end);
+ }
+
+ public function this($pointer = 'future')
+ {
+ parent::this($pointer);
+
+ switch ($pointer) {
+ case 'future':
+ $hourStart = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min + 1));
+ $hourEnd = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour + 1));
+ break;
+
+ case 'past':
+ $hourStart = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour));
+ $hourEnd = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour + 1, 'min' => $this->now->min));
+ break;
+
+ case 'none':
+ $hourStart = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour));
+ $hourEnd = clone($hourStart);
+ $hourEnd->hour++;
+ break;
+ }
+
+ return new Horde_Date_Span($hourStart, $hourEnd);
+ }
+
+ public function offset($span, $amount, $pointer)
+ {
+ $direction = ($pointer == 'future') ? 1 : -1;
+ return $span->add(array('hour' => $direction * $amount));
+ }
+
+ public function width()
+ {
+ return 3600;
+ }
+
+ public function __toString()
+ {
+ return parent::__toString() . '-hour';
+ }
+
+}
<?php
class Horde_Date_Parser_Locale_Base_Repeater_Minute extends Horde_Date_Parser_Locale_Base_Repeater
{
- MINUTE_SECONDS = 60
-
- def next(pointer = :future)
- super
-
- if !@current_minute_start
- case pointer
- when :future
- @current_minute_start = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
- when :past
- @current_minute_start = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min - 1)
- end
- else
- direction = pointer == :future ? 1 : -1
- @current_minute_start += direction * MINUTE_SECONDS
- end
-
- Chronic::Span.new(@current_minute_start, @current_minute_start + MINUTE_SECONDS)
- end
-
- def this(pointer = :future)
- super
-
- case pointer
- when :future
- minute_begin = @now
- minute_end = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
- when :past
- minute_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
- minute_end = @now
- when :none
- minute_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
- minute_end = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min) + MINUTE_SECONDS
- end
-
- Chronic::Span.new(minute_begin, minute_end)
- end
-
- def offset(span, amount, pointer)
- direction = pointer == :future ? 1 : -1
- span + direction * amount * MINUTE_SECONDS
- end
-
- def width
- MINUTE_SECONDS
- end
-
- def to_s
- super << '-minute'
- end
-end
\ No newline at end of file
+ public $currentMinuteStart;
+
+ public function next($pointer = 'future')
+ {
+ parent::next($pointer);
+
+ if (!$this->currentMinuteStart) {
+ $this->currentMinuteStart = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
+ }
+ $direction = ($pointer == 'future') ? 1 : -1;
+ $this->currentMinuteStart->min += $direction;
+
+ $end = clone($this->currentMinuteStart);
+ $end->min++;
+ return new Horde_Date_Span($this->currentMinuteStart, $end);
+ }
+
+ public function this($pointer = 'future')
+ {
+ parent::this($pointer);
+
+ switch ($pointer) {
+ case 'future':
+ $minuteBegin = clone($this->now);
+ $minuteEnd = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
+ break;
+
+ case 'past':
+ $minuteBegin = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
+ $minuteEnd = clone($this->now);
+ break;
+
+ case 'none':
+ $minuteBegin = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
+ $minuteEnd = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min + 1));
+ break;
+ }
+
+ return new Horde_Date_Span($minuteBegin, $minuteEnd);
+ }
+
+ public function offset($span, $amount, $pointer)
+ {
+ $direction = ($pointer == 'future') ? 1 : -1;
+ return $span->add(array('min' => $diretion * $amount));
+ }
+
+ public function width()
+ {
+ return 60;
+ }
+
+ public function __toString()
+ {
+ return parent::__toString() . '-minute';
+ }
+
+}
<?php
class Horde_Date_Parser_Locale_Base_Repeater_Second extends Horde_Date_Parser_Locale_Base_Repeater
{
- const SECOND_SECONDS = 1;
-
- def next(pointer = :future)
- super
-
- direction = pointer == :future ? 1 : -1
-
- if !@second_start
- @second_start = @now + (direction * SECOND_SECONDS)
- else
- @second_start += SECOND_SECONDS * direction
- end
-
- Chronic::Span.new(@second_start, @second_start + SECOND_SECONDS)
- end
-
- def this(pointer = :future)
- super
-
- Chronic::Span.new(@now, @now + 1)
- end
-
- def offset(span, amount, pointer)
- direction = pointer == :future ? 1 : -1
- span + direction * amount * SECOND_SECONDS
- end
-
- def width
- SECOND_SECONDS
- end
-
- def to_s
- super << '-second'
- end
-end
+ public $secondStart;
+
+ public function next($pointer = 'future')
+ {
+ parent::next($pointer);
+
+ $direction = ($pointer == 'future') ? 1 : -1;
+
+ if (!$this->secondStart) {
+ $this->secondStart = clone($this->now);
+ $this->secondStart->sec += $direction;
+ } else {
+ $this->secondStart += $direction;
+ }
+
+ $end = clone($this->secondStart);
+ $end->sec++;
+ return new Horde_Date_Span($this->secondStart, $end);
+ }
+
+ public function this($pointer = 'future')
+ {
+ parent::this($pointer);
+
+ $end = clone($this->now);
+ $end->sec++;
+ return new Horde_Date_Span($this->now, $end);
+ }
+
+ public function offset($span, $amount, $pointer)
+ {
+ $direction = ($pointer == 'future') ? 1 : -1;
+ return $span->add($direction * $amount);
+ }
+
+ public function width()
+ {
+ return 1;
+ }
+
+ public function __toString()
+ {
+ return parent::__toString() . '-second';
+ }
+
+}