repeaters -> repeater for autoloadable dir structure
authorChuck Hagenbuch <chuck@horde.org>
Thu, 29 Jan 2009 16:48:54 +0000 (11:48 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Thu, 29 Jan 2009 22:13:03 +0000 (17:13 -0500)
30 files changed:
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Day.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/DayName.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/DayPortion.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Fortnight.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Hour.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Minute.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Month.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/MonthName.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Season.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/SeasonName.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Second.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Time.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Week.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Weekend.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Year.php [new file with mode: 0644]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Day.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/DayName.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/DayPortion.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Fortnight.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Hour.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Minute.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Month.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/MonthName.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Season.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/SeasonName.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Second.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Time.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Week.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Weekend.php [deleted file]
framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Year.php [deleted file]

diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Day.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Day.php
new file mode 100644 (file)
index 0000000..a92d83f
--- /dev/null
@@ -0,0 +1,47 @@
+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
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/DayName.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/DayName.php
new file mode 100644 (file)
index 0000000..0486a4d
--- /dev/null
@@ -0,0 +1,46 @@
+class Chronic::RepeaterDayName < Chronic::Repeater #:nodoc:
+  DAY_SECONDS = 86400 # (24 * 60 * 60)
+  
+  def next(pointer)
+    super
+    
+    direction = pointer == :future ? 1 : -1
+    
+    if !@current_day_start
+      @current_day_start = Time.construct(@now.year, @now.month, @now.day)
+      @current_day_start += direction * DAY_SECONDS
+
+      day_num = symbol_to_number(@type)
+      
+      while @current_day_start.wday != day_num
+        @current_day_start += direction * DAY_SECONDS
+      end
+    else
+      @current_day_start += direction * 7 * DAY_SECONDS
+    end
+    
+    Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
+  end
+  
+  def this(pointer = :future)
+    super
+    
+    pointer = :future if pointer == :none
+    self.next(pointer)
+  end
+  
+  def width
+    DAY_SECONDS
+  end
+  
+  def to_s
+    super << '-dayname-' << @type.to_s
+  end
+  
+  private
+  
+  def symbol_to_number(sym)
+    lookup = {:sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3, :thursday => 4, :friday => 5, :saturday => 6}
+    lookup[sym] || raise("Invalid symbol specified")
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/DayPortion.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/DayPortion.php
new file mode 100644 (file)
index 0000000..c854933
--- /dev/null
@@ -0,0 +1,93 @@
+class Chronic::RepeaterDayPortion < Chronic::Repeater #:nodoc:
+  @@morning = (6 * 60 * 60)..(12 * 60 * 60) # 6am-12am
+  @@afternoon = (13 * 60 * 60)..(17 * 60 * 60) # 1pm-5pm
+  @@evening = (17 * 60 * 60)..(20 * 60 * 60) # 5pm-8pm
+  @@night = (20 * 60 * 60)..(24 * 60 * 60) # 8pm-12pm
+  
+  def initialize(type)
+    super
+    
+    if type.kind_of? Integer
+      @range = (@type * 60 * 60)..((@type + 12) * 60 * 60)
+    else
+      lookup = {:am => 0..(12 * 60 * 60 - 1),
+                :pm => (12 * 60 * 60)..(24 * 60 * 60 - 1),
+                :morning => @@morning,
+                :afternoon => @@afternoon,
+                :evening => @@evening,
+                :night => @@night}
+      @range = lookup[type]
+      lookup[type] || raise("Invalid type '#{type}' for RepeaterDayPortion")
+    end
+    @range || raise("Range should have been set by now")
+  end
+  
+  def next(pointer)
+    super
+    
+    full_day = 60 * 60 * 24
+    
+    if !@current_span
+      now_seconds = @now - Time.construct(@now.year, @now.month, @now.day)
+      if now_seconds < @range.begin
+        case pointer
+        when :future
+          range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
+        when :past
+          range_start = Time.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
+        end
+      elsif now_seconds > @range.end
+        case pointer
+        when :future
+          range_start = Time.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
+        when :past
+          range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
+        end
+      else
+        case pointer
+        when :future
+          range_start = Time.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
+        when :past
+          range_start = Time.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
+        end
+      end
+      
+      @current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
+    else
+      case pointer
+      when :future
+        @current_span += full_day
+      when :past
+        @current_span -= full_day
+      end
+    end
+  end
+  
+  def this(context = :future)
+    super
+    
+    range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
+    @current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
+  end
+  
+  def offset(span, amount, pointer)
+    @now = span.begin
+    portion_span = self.next(pointer)
+    direction = pointer == :future ? 1 : -1
+    portion_span + (direction * (amount - 1) * Chronic::RepeaterDay::DAY_SECONDS)
+  end
+  
+  def width
+    @range || raise("Range has not been set")
+    return @current_span.width if @current_span
+    if @type.kind_of? Integer
+      return (12 * 60 * 60)
+    else
+      @range.end - @range.begin
+    end
+  end
+  
+  def to_s
+    super << '-dayportion-' << @type.to_s
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Fortnight.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Fortnight.php
new file mode 100644 (file)
index 0000000..058fbb9
--- /dev/null
@@ -0,0 +1,65 @@
+class Chronic::RepeaterFortnight < Chronic::Repeater #:nodoc:
+  FORTNIGHT_SECONDS = 1_209_600 # (14 * 24 * 60 * 60)
+  
+  def next(pointer)
+    super
+    
+    if !@current_fortnight_start
+      case pointer
+      when :future
+        sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
+        sunday_repeater.start = @now
+        next_sunday_span = sunday_repeater.next(:future)
+        @current_fortnight_start = next_sunday_span.begin
+      when :past
+        sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
+        sunday_repeater.start = (@now + Chronic::RepeaterDay::DAY_SECONDS)
+        2.times { sunday_repeater.next(:past) }
+        last_sunday_span = sunday_repeater.next(:past)
+        @current_fortnight_start = last_sunday_span.begin
+      end
+    else
+      direction = pointer == :future ? 1 : -1
+      @current_fortnight_start += direction * FORTNIGHT_SECONDS
+    end
+    
+    Chronic::Span.new(@current_fortnight_start, @current_fortnight_start + FORTNIGHT_SECONDS)
+  end
+  
+  def this(pointer = :future)
+    super
+    
+    pointer = :future if pointer == :none
+    
+    case pointer
+    when :future
+      this_fortnight_start = Time.construct(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
+      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
+      sunday_repeater.start = @now
+      sunday_repeater.this(:future)
+      this_sunday_span = sunday_repeater.this(:future)
+      this_fortnight_end = this_sunday_span.begin
+      Chronic::Span.new(this_fortnight_start, this_fortnight_end)
+    when :past
+      this_fortnight_end = Time.construct(@now.year, @now.month, @now.day, @now.hour)
+      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
+      sunday_repeater.start = @now
+      last_sunday_span = sunday_repeater.next(:past)
+      this_fortnight_start = last_sunday_span.begin
+      Chronic::Span.new(this_fortnight_start, this_fortnight_end)
+    end
+  end
+  
+  def offset(span, amount, pointer)
+    direction = pointer == :future ? 1 : -1
+    span + direction * amount * FORTNIGHT_SECONDS
+  end
+
+  def width
+    FORTNIGHT_SECONDS
+  end
+  
+  def to_s
+    super << '-fortnight'
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Hour.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Hour.php
new file mode 100644 (file)
index 0000000..f38a3f8
--- /dev/null
@@ -0,0 +1,52 @@
+class Chronic::RepeaterHour < Chronic::Repeater #:nodoc:
+  HOUR_SECONDS = 3600 # 60 * 60
+  
+  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
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Minute.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Minute.php
new file mode 100644 (file)
index 0000000..342d3cd
--- /dev/null
@@ -0,0 +1,52 @@
+class Chronic::RepeaterMinute < Chronic::Repeater #:nodoc:
+  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
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Month.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Month.php
new file mode 100644 (file)
index 0000000..edd89ee
--- /dev/null
@@ -0,0 +1,61 @@
+class Chronic::RepeaterMonth < Chronic::Repeater #:nodoc:
+  MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
+  YEAR_MONTHS = 12
+  
+  def next(pointer)
+    super
+    
+    if !@current_month_start
+      @current_month_start = offset_by(Time.construct(@now.year, @now.month), 1, pointer)
+    else
+      @current_month_start = offset_by(Time.construct(@current_month_start.year, @current_month_start.month), 1, pointer)
+    end
+    
+    Chronic::Span.new(@current_month_start, Time.construct(@current_month_start.year, @current_month_start.month + 1))
+  end
+  
+  def this(pointer = :future)
+    super
+    
+    case pointer
+    when :future
+      month_start = Time.construct(@now.year, @now.month, @now.day + 1)
+      month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
+    when :past
+      month_start = Time.construct(@now.year, @now.month)
+      month_end = Time.construct(@now.year, @now.month, @now.day)
+    when :none
+      month_start = Time.construct(@now.year, @now.month)
+      month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
+    end
+    
+    Chronic::Span.new(month_start, month_end)
+  end
+  
+  def offset(span, amount, pointer)      
+    Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
+  end
+  
+  def offset_by(time, amount, pointer) 
+    direction = pointer == :future ? 1 : -1
+    
+    amount_years = direction * amount / YEAR_MONTHS
+    amount_months = direction * amount % YEAR_MONTHS
+    
+    new_year = time.year + amount_years
+    new_month = time.month + amount_months
+    if new_month > YEAR_MONTHS
+      new_year += 1
+      new_month -= YEAR_MONTHS
+    end
+    Time.construct(new_year, new_month, time.day, time.hour, time.min, time.sec)
+  end
+  
+  def width
+    MONTH_SECONDS
+  end
+  
+  def to_s
+    super << '-month'
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/MonthName.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/MonthName.php
new file mode 100644 (file)
index 0000000..1f8b748
--- /dev/null
@@ -0,0 +1,93 @@
+class Chronic::RepeaterMonthName < Chronic::Repeater #:nodoc:
+  MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
+  
+  def next(pointer)
+    super
+    
+    if !@current_month_begin
+      target_month = symbol_to_number(@type)
+      case pointer
+      when :future
+        if @now.month < target_month
+          @current_month_begin = Time.construct(@now.year, target_month)
+        else @now.month > target_month
+          @current_month_begin = Time.construct(@now.year + 1, target_month)
+        end
+      when :none
+        if @now.month <= target_month
+          @current_month_begin = Time.construct(@now.year, target_month)
+        else @now.month > target_month
+          @current_month_begin = Time.construct(@now.year + 1, target_month)
+        end
+      when :past
+        if @now.month > target_month
+          @current_month_begin = Time.construct(@now.year, target_month)
+        else @now.month < target_month
+          @current_month_begin = Time.construct(@now.year - 1, target_month)
+        end
+      end
+      @current_month_begin || raise("Current month should be set by now")
+    else
+      case pointer
+      when :future
+        @current_month_begin = Time.construct(@current_month_begin.year + 1, @current_month_begin.month)
+      when :past
+        @current_month_begin = Time.construct(@current_month_begin.year - 1, @current_month_begin.month)
+      end
+    end
+    
+    cur_month_year = @current_month_begin.year
+    cur_month_month = @current_month_begin.month
+    
+    if cur_month_month == 12
+      next_month_year = cur_month_year + 1
+      next_month_month = 1
+    else
+      next_month_year = cur_month_year
+      next_month_month = cur_month_month + 1
+    end
+      
+    Chronic::Span.new(@current_month_begin, Time.construct(next_month_year, next_month_month))
+  end
+  
+  def this(pointer = :future)
+    super
+    
+    case pointer
+    when :past
+      self.next(pointer)
+    when :future, :none
+      self.next(:none)
+    end
+  end
+  
+  def width
+    MONTH_SECONDS
+  end
+  
+  def index
+    symbol_to_number(@type)
+  end
+  
+  def to_s
+    super << '-monthname-' << @type.to_s
+  end
+  
+  private
+  
+  def symbol_to_number(sym)
+    lookup = {:january => 1,
+              :february => 2,
+              :march => 3,
+              :april => 4,
+              :may => 5,
+              :june => 6,
+              :july => 7,
+              :august => 8,
+              :september => 9,
+              :october => 10,
+              :november => 11,
+              :december => 12}
+    lookup[sym] || raise("Invalid symbol specified")
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Season.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Season.php
new file mode 100644 (file)
index 0000000..a255865
--- /dev/null
@@ -0,0 +1,23 @@
+class Chronic::RepeaterSeason < Chronic::Repeater #:nodoc:
+  SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
+  
+  def next(pointer)
+    super
+    
+    raise 'Not implemented'
+  end
+  
+  def this(pointer = :future)
+    super
+    
+    raise 'Not implemented'
+  end
+  
+  def width
+    SEASON_SECONDS
+  end
+  
+  def to_s
+    super << '-season'
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/SeasonName.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/SeasonName.php
new file mode 100644 (file)
index 0000000..adfd1f2
--- /dev/null
@@ -0,0 +1,24 @@
+class Chronic::RepeaterSeasonName < Chronic::RepeaterSeason #:nodoc:
+  @summer = ['jul 21', 'sep 22']
+  @autumn = ['sep 23', 'dec 21']
+  @winter = ['dec 22', 'mar 19']
+  @spring = ['mar 20', 'jul 20']
+  
+  def next(pointer)
+    super
+    raise 'Not implemented'
+  end
+  
+  def this(pointer = :future)
+    super
+    raise 'Not implemented'
+  end
+  
+  def width
+    (91 * 24 * 60 * 60)
+  end
+  
+  def to_s
+    super << '-season-' << @type.to_s
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Second.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Second.php
new file mode 100644 (file)
index 0000000..6d05545
--- /dev/null
@@ -0,0 +1,36 @@
+class Chronic::RepeaterSecond < Chronic::Repeater #:nodoc:
+  SECOND_SECONDS = 1 # haha, awesome
+  
+  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
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Time.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Time.php
new file mode 100644 (file)
index 0000000..f856014
--- /dev/null
@@ -0,0 +1,117 @@
+class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
+  class Tick #:nodoc:
+    attr_accessor :time
+    
+    def initialize(time, ambiguous = false)
+      @time = time
+      @ambiguous = ambiguous
+    end
+    
+    def ambiguous?
+      @ambiguous
+    end
+    
+    def *(other)
+      Tick.new(@time * other, @ambiguous)
+    end
+    
+    def to_f
+      @time.to_f
+    end
+    
+    def to_s
+      @time.to_s + (@ambiguous ? '?' : '')
+    end
+  end
+  
+  def initialize(time, options = {})
+    t = time.gsub(/\:/, '')
+    @type = 
+    if (1..2) === t.size
+      hours = t.to_i
+      hours == 12 ? Tick.new(0 * 60 * 60, true) : Tick.new(hours * 60 * 60, true)
+    elsif t.size == 3
+      Tick.new((t[0..0].to_i * 60 * 60) + (t[1..2].to_i * 60), true)
+    elsif t.size == 4
+      ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
+      hours = t[0..1].to_i
+      hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60, ambiguous)
+    elsif t.size == 5
+      Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
+    elsif t.size == 6
+      ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
+      hours = t[0..1].to_i
+      hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
+    else
+      raise("Time cannot exceed six digits")
+    end
+  end
+  
+  # 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
+  def next(pointer)
+    super
+    
+    half_day = 60 * 60 * 12
+    full_day = 60 * 60 * 24
+    
+    first = false
+    
+    unless @current_time
+      first = true
+      midnight = Time.local(@now.year, @now.month, @now.day)
+      yesterday_midnight = midnight - full_day
+      tomorrow_midnight = midnight + full_day
+
+      catch :done do
+        if pointer == :future
+          if @type.ambiguous?
+            [midnight + @type, midnight + half_day + @type, tomorrow_midnight + @type].each do |t|
+              (@current_time = t; throw :done) if t >= @now
+            end
+          else
+            [midnight + @type, tomorrow_midnight + @type].each do |t|
+              (@current_time = t; throw :done) if t >= @now
+            end
+          end
+        else # pointer == :past
+          if @type.ambiguous?
+            [midnight + half_day + @type, midnight + @type, yesterday_midnight + @type * 2].each do |t|
+              (@current_time = t; throw :done) if t <= @now
+            end
+          else
+            [midnight + @type, yesterday_midnight + @type].each do |t|
+              (@current_time = t; throw :done) if t <= @now
+            end
+          end
+        end
+      end
+      
+      @current_time || raise("Current time cannot be nil at this point")
+    end
+    
+    unless first
+      increment = @type.ambiguous? ? half_day : full_day
+      @current_time += pointer == :future ? increment : -increment
+    end
+    
+    Chronic::Span.new(@current_time, @current_time + width)
+  end
+  
+  def this(context = :future)
+    super
+    
+    context = :future if context == :none
+    
+    self.next(context)
+  end
+  
+  def width
+    1
+  end
+  
+  def to_s
+    super << '-time-' << @type.to_s
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Week.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Week.php
new file mode 100644 (file)
index 0000000..ec88ff1
--- /dev/null
@@ -0,0 +1,68 @@
+class Chronic::RepeaterWeek < Chronic::Repeater #:nodoc:
+  WEEK_SECONDS = 604800 # (7 * 24 * 60 * 60)
+  
+  def next(pointer)
+    super
+    
+    if !@current_week_start
+      case pointer
+      when :future
+        sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
+        sunday_repeater.start = @now
+        next_sunday_span = sunday_repeater.next(:future)
+        @current_week_start = next_sunday_span.begin
+      when :past
+        sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
+        sunday_repeater.start = (@now + Chronic::RepeaterDay::DAY_SECONDS)
+        sunday_repeater.next(:past)
+        last_sunday_span = sunday_repeater.next(:past)
+        @current_week_start = last_sunday_span.begin
+      end
+    else
+      direction = pointer == :future ? 1 : -1
+      @current_week_start += direction * WEEK_SECONDS
+    end
+    
+    Chronic::Span.new(@current_week_start, @current_week_start + WEEK_SECONDS)
+  end
+  
+  def this(pointer = :future)
+    super
+    
+    case pointer
+    when :future
+      this_week_start = Time.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
+      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
+      sunday_repeater.start = @now
+      this_sunday_span = sunday_repeater.this(:future)
+      this_week_end = this_sunday_span.begin
+      Chronic::Span.new(this_week_start, this_week_end)
+    when :past
+      this_week_end = Time.local(@now.year, @now.month, @now.day, @now.hour)
+      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
+      sunday_repeater.start = @now
+      last_sunday_span = sunday_repeater.next(:past)
+      this_week_start = last_sunday_span.begin
+      Chronic::Span.new(this_week_start, this_week_end)
+    when :none
+      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
+      sunday_repeater.start = @now
+      last_sunday_span = sunday_repeater.next(:past)
+      this_week_start = last_sunday_span.begin
+      Chronic::Span.new(this_week_start, this_week_start + WEEK_SECONDS)
+    end
+  end
+  
+  def offset(span, amount, pointer)
+    direction = pointer == :future ? 1 : -1
+    span + direction * amount * WEEK_SECONDS
+  end
+  
+  def width
+    WEEK_SECONDS
+  end
+  
+  def to_s
+    super << '-week'
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Weekend.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Weekend.php
new file mode 100644 (file)
index 0000000..f012267
--- /dev/null
@@ -0,0 +1,60 @@
+class Chronic::RepeaterWeekend < Chronic::Repeater #:nodoc:
+  WEEKEND_SECONDS = 172_800 # (2 * 24 * 60 * 60)
+  
+  def next(pointer)
+    super
+    
+    if !@current_week_start
+      case pointer
+      when :future
+        saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
+        saturday_repeater.start = @now
+        next_saturday_span = saturday_repeater.next(:future)
+        @current_week_start = next_saturday_span.begin
+      when :past
+        saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
+        saturday_repeater.start = (@now + Chronic::RepeaterDay::DAY_SECONDS)
+        last_saturday_span = saturday_repeater.next(:past)
+        @current_week_start = last_saturday_span.begin
+      end
+    else
+      direction = pointer == :future ? 1 : -1
+      @current_week_start += direction * Chronic::RepeaterWeek::WEEK_SECONDS
+    end
+    
+    Chronic::Span.new(@current_week_start, @current_week_start + WEEKEND_SECONDS)
+  end
+  
+  def this(pointer = :future)
+    super
+    
+    case pointer
+    when :future, :none
+      saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
+      saturday_repeater.start = @now
+      this_saturday_span = saturday_repeater.this(:future)
+      Chronic::Span.new(this_saturday_span.begin, this_saturday_span.begin + WEEKEND_SECONDS)
+    when :past
+      saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
+      saturday_repeater.start = @now
+      last_saturday_span = saturday_repeater.this(:past)
+      Chronic::Span.new(last_saturday_span.begin, last_saturday_span.begin + WEEKEND_SECONDS)
+    end
+  end
+  
+  def offset(span, amount, pointer)
+    direction = pointer == :future ? 1 : -1
+    weekend = Chronic::RepeaterWeekend.new(:weekend)
+    weekend.start = span.begin
+    start = weekend.next(pointer).begin + (amount - 1) * direction * Chronic::RepeaterWeek::WEEK_SECONDS
+    Chronic::Span.new(start, start + (span.end - span.begin))
+  end
+  
+  def width
+    WEEKEND_SECONDS
+  end
+  
+  def to_s
+    super << '-weekend'
+  end
+end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Year.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Year.php
new file mode 100644 (file)
index 0000000..426371f
--- /dev/null
@@ -0,0 +1,58 @@
+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
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Day.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Day.php
deleted file mode 100644 (file)
index a92d83f..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-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
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/DayName.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/DayName.php
deleted file mode 100644 (file)
index 0486a4d..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-class Chronic::RepeaterDayName < Chronic::Repeater #:nodoc:
-  DAY_SECONDS = 86400 # (24 * 60 * 60)
-  
-  def next(pointer)
-    super
-    
-    direction = pointer == :future ? 1 : -1
-    
-    if !@current_day_start
-      @current_day_start = Time.construct(@now.year, @now.month, @now.day)
-      @current_day_start += direction * DAY_SECONDS
-
-      day_num = symbol_to_number(@type)
-      
-      while @current_day_start.wday != day_num
-        @current_day_start += direction * DAY_SECONDS
-      end
-    else
-      @current_day_start += direction * 7 * DAY_SECONDS
-    end
-    
-    Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
-  end
-  
-  def this(pointer = :future)
-    super
-    
-    pointer = :future if pointer == :none
-    self.next(pointer)
-  end
-  
-  def width
-    DAY_SECONDS
-  end
-  
-  def to_s
-    super << '-dayname-' << @type.to_s
-  end
-  
-  private
-  
-  def symbol_to_number(sym)
-    lookup = {:sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3, :thursday => 4, :friday => 5, :saturday => 6}
-    lookup[sym] || raise("Invalid symbol specified")
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/DayPortion.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/DayPortion.php
deleted file mode 100644 (file)
index c854933..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-class Chronic::RepeaterDayPortion < Chronic::Repeater #:nodoc:
-  @@morning = (6 * 60 * 60)..(12 * 60 * 60) # 6am-12am
-  @@afternoon = (13 * 60 * 60)..(17 * 60 * 60) # 1pm-5pm
-  @@evening = (17 * 60 * 60)..(20 * 60 * 60) # 5pm-8pm
-  @@night = (20 * 60 * 60)..(24 * 60 * 60) # 8pm-12pm
-  
-  def initialize(type)
-    super
-    
-    if type.kind_of? Integer
-      @range = (@type * 60 * 60)..((@type + 12) * 60 * 60)
-    else
-      lookup = {:am => 0..(12 * 60 * 60 - 1),
-                :pm => (12 * 60 * 60)..(24 * 60 * 60 - 1),
-                :morning => @@morning,
-                :afternoon => @@afternoon,
-                :evening => @@evening,
-                :night => @@night}
-      @range = lookup[type]
-      lookup[type] || raise("Invalid type '#{type}' for RepeaterDayPortion")
-    end
-    @range || raise("Range should have been set by now")
-  end
-  
-  def next(pointer)
-    super
-    
-    full_day = 60 * 60 * 24
-    
-    if !@current_span
-      now_seconds = @now - Time.construct(@now.year, @now.month, @now.day)
-      if now_seconds < @range.begin
-        case pointer
-        when :future
-          range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
-        when :past
-          range_start = Time.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
-        end
-      elsif now_seconds > @range.end
-        case pointer
-        when :future
-          range_start = Time.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
-        when :past
-          range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
-        end
-      else
-        case pointer
-        when :future
-          range_start = Time.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
-        when :past
-          range_start = Time.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
-        end
-      end
-      
-      @current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
-    else
-      case pointer
-      when :future
-        @current_span += full_day
-      when :past
-        @current_span -= full_day
-      end
-    end
-  end
-  
-  def this(context = :future)
-    super
-    
-    range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
-    @current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
-  end
-  
-  def offset(span, amount, pointer)
-    @now = span.begin
-    portion_span = self.next(pointer)
-    direction = pointer == :future ? 1 : -1
-    portion_span + (direction * (amount - 1) * Chronic::RepeaterDay::DAY_SECONDS)
-  end
-  
-  def width
-    @range || raise("Range has not been set")
-    return @current_span.width if @current_span
-    if @type.kind_of? Integer
-      return (12 * 60 * 60)
-    else
-      @range.end - @range.begin
-    end
-  end
-  
-  def to_s
-    super << '-dayportion-' << @type.to_s
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Fortnight.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Fortnight.php
deleted file mode 100644 (file)
index 058fbb9..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-class Chronic::RepeaterFortnight < Chronic::Repeater #:nodoc:
-  FORTNIGHT_SECONDS = 1_209_600 # (14 * 24 * 60 * 60)
-  
-  def next(pointer)
-    super
-    
-    if !@current_fortnight_start
-      case pointer
-      when :future
-        sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
-        sunday_repeater.start = @now
-        next_sunday_span = sunday_repeater.next(:future)
-        @current_fortnight_start = next_sunday_span.begin
-      when :past
-        sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
-        sunday_repeater.start = (@now + Chronic::RepeaterDay::DAY_SECONDS)
-        2.times { sunday_repeater.next(:past) }
-        last_sunday_span = sunday_repeater.next(:past)
-        @current_fortnight_start = last_sunday_span.begin
-      end
-    else
-      direction = pointer == :future ? 1 : -1
-      @current_fortnight_start += direction * FORTNIGHT_SECONDS
-    end
-    
-    Chronic::Span.new(@current_fortnight_start, @current_fortnight_start + FORTNIGHT_SECONDS)
-  end
-  
-  def this(pointer = :future)
-    super
-    
-    pointer = :future if pointer == :none
-    
-    case pointer
-    when :future
-      this_fortnight_start = Time.construct(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
-      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
-      sunday_repeater.start = @now
-      sunday_repeater.this(:future)
-      this_sunday_span = sunday_repeater.this(:future)
-      this_fortnight_end = this_sunday_span.begin
-      Chronic::Span.new(this_fortnight_start, this_fortnight_end)
-    when :past
-      this_fortnight_end = Time.construct(@now.year, @now.month, @now.day, @now.hour)
-      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
-      sunday_repeater.start = @now
-      last_sunday_span = sunday_repeater.next(:past)
-      this_fortnight_start = last_sunday_span.begin
-      Chronic::Span.new(this_fortnight_start, this_fortnight_end)
-    end
-  end
-  
-  def offset(span, amount, pointer)
-    direction = pointer == :future ? 1 : -1
-    span + direction * amount * FORTNIGHT_SECONDS
-  end
-
-  def width
-    FORTNIGHT_SECONDS
-  end
-  
-  def to_s
-    super << '-fortnight'
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Hour.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Hour.php
deleted file mode 100644 (file)
index f38a3f8..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-class Chronic::RepeaterHour < Chronic::Repeater #:nodoc:
-  HOUR_SECONDS = 3600 # 60 * 60
-  
-  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
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Minute.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Minute.php
deleted file mode 100644 (file)
index 342d3cd..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-class Chronic::RepeaterMinute < Chronic::Repeater #:nodoc:
-  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
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Month.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Month.php
deleted file mode 100644 (file)
index edd89ee..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-class Chronic::RepeaterMonth < Chronic::Repeater #:nodoc:
-  MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
-  YEAR_MONTHS = 12
-  
-  def next(pointer)
-    super
-    
-    if !@current_month_start
-      @current_month_start = offset_by(Time.construct(@now.year, @now.month), 1, pointer)
-    else
-      @current_month_start = offset_by(Time.construct(@current_month_start.year, @current_month_start.month), 1, pointer)
-    end
-    
-    Chronic::Span.new(@current_month_start, Time.construct(@current_month_start.year, @current_month_start.month + 1))
-  end
-  
-  def this(pointer = :future)
-    super
-    
-    case pointer
-    when :future
-      month_start = Time.construct(@now.year, @now.month, @now.day + 1)
-      month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
-    when :past
-      month_start = Time.construct(@now.year, @now.month)
-      month_end = Time.construct(@now.year, @now.month, @now.day)
-    when :none
-      month_start = Time.construct(@now.year, @now.month)
-      month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
-    end
-    
-    Chronic::Span.new(month_start, month_end)
-  end
-  
-  def offset(span, amount, pointer)      
-    Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
-  end
-  
-  def offset_by(time, amount, pointer) 
-    direction = pointer == :future ? 1 : -1
-    
-    amount_years = direction * amount / YEAR_MONTHS
-    amount_months = direction * amount % YEAR_MONTHS
-    
-    new_year = time.year + amount_years
-    new_month = time.month + amount_months
-    if new_month > YEAR_MONTHS
-      new_year += 1
-      new_month -= YEAR_MONTHS
-    end
-    Time.construct(new_year, new_month, time.day, time.hour, time.min, time.sec)
-  end
-  
-  def width
-    MONTH_SECONDS
-  end
-  
-  def to_s
-    super << '-month'
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/MonthName.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/MonthName.php
deleted file mode 100644 (file)
index 1f8b748..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-class Chronic::RepeaterMonthName < Chronic::Repeater #:nodoc:
-  MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
-  
-  def next(pointer)
-    super
-    
-    if !@current_month_begin
-      target_month = symbol_to_number(@type)
-      case pointer
-      when :future
-        if @now.month < target_month
-          @current_month_begin = Time.construct(@now.year, target_month)
-        else @now.month > target_month
-          @current_month_begin = Time.construct(@now.year + 1, target_month)
-        end
-      when :none
-        if @now.month <= target_month
-          @current_month_begin = Time.construct(@now.year, target_month)
-        else @now.month > target_month
-          @current_month_begin = Time.construct(@now.year + 1, target_month)
-        end
-      when :past
-        if @now.month > target_month
-          @current_month_begin = Time.construct(@now.year, target_month)
-        else @now.month < target_month
-          @current_month_begin = Time.construct(@now.year - 1, target_month)
-        end
-      end
-      @current_month_begin || raise("Current month should be set by now")
-    else
-      case pointer
-      when :future
-        @current_month_begin = Time.construct(@current_month_begin.year + 1, @current_month_begin.month)
-      when :past
-        @current_month_begin = Time.construct(@current_month_begin.year - 1, @current_month_begin.month)
-      end
-    end
-    
-    cur_month_year = @current_month_begin.year
-    cur_month_month = @current_month_begin.month
-    
-    if cur_month_month == 12
-      next_month_year = cur_month_year + 1
-      next_month_month = 1
-    else
-      next_month_year = cur_month_year
-      next_month_month = cur_month_month + 1
-    end
-      
-    Chronic::Span.new(@current_month_begin, Time.construct(next_month_year, next_month_month))
-  end
-  
-  def this(pointer = :future)
-    super
-    
-    case pointer
-    when :past
-      self.next(pointer)
-    when :future, :none
-      self.next(:none)
-    end
-  end
-  
-  def width
-    MONTH_SECONDS
-  end
-  
-  def index
-    symbol_to_number(@type)
-  end
-  
-  def to_s
-    super << '-monthname-' << @type.to_s
-  end
-  
-  private
-  
-  def symbol_to_number(sym)
-    lookup = {:january => 1,
-              :february => 2,
-              :march => 3,
-              :april => 4,
-              :may => 5,
-              :june => 6,
-              :july => 7,
-              :august => 8,
-              :september => 9,
-              :october => 10,
-              :november => 11,
-              :december => 12}
-    lookup[sym] || raise("Invalid symbol specified")
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Season.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Season.php
deleted file mode 100644 (file)
index a255865..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-class Chronic::RepeaterSeason < Chronic::Repeater #:nodoc:
-  SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
-  
-  def next(pointer)
-    super
-    
-    raise 'Not implemented'
-  end
-  
-  def this(pointer = :future)
-    super
-    
-    raise 'Not implemented'
-  end
-  
-  def width
-    SEASON_SECONDS
-  end
-  
-  def to_s
-    super << '-season'
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/SeasonName.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/SeasonName.php
deleted file mode 100644 (file)
index adfd1f2..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-class Chronic::RepeaterSeasonName < Chronic::RepeaterSeason #:nodoc:
-  @summer = ['jul 21', 'sep 22']
-  @autumn = ['sep 23', 'dec 21']
-  @winter = ['dec 22', 'mar 19']
-  @spring = ['mar 20', 'jul 20']
-  
-  def next(pointer)
-    super
-    raise 'Not implemented'
-  end
-  
-  def this(pointer = :future)
-    super
-    raise 'Not implemented'
-  end
-  
-  def width
-    (91 * 24 * 60 * 60)
-  end
-  
-  def to_s
-    super << '-season-' << @type.to_s
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Second.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Second.php
deleted file mode 100644 (file)
index 6d05545..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-class Chronic::RepeaterSecond < Chronic::Repeater #:nodoc:
-  SECOND_SECONDS = 1 # haha, awesome
-  
-  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
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Time.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Time.php
deleted file mode 100644 (file)
index f856014..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
-  class Tick #:nodoc:
-    attr_accessor :time
-    
-    def initialize(time, ambiguous = false)
-      @time = time
-      @ambiguous = ambiguous
-    end
-    
-    def ambiguous?
-      @ambiguous
-    end
-    
-    def *(other)
-      Tick.new(@time * other, @ambiguous)
-    end
-    
-    def to_f
-      @time.to_f
-    end
-    
-    def to_s
-      @time.to_s + (@ambiguous ? '?' : '')
-    end
-  end
-  
-  def initialize(time, options = {})
-    t = time.gsub(/\:/, '')
-    @type = 
-    if (1..2) === t.size
-      hours = t.to_i
-      hours == 12 ? Tick.new(0 * 60 * 60, true) : Tick.new(hours * 60 * 60, true)
-    elsif t.size == 3
-      Tick.new((t[0..0].to_i * 60 * 60) + (t[1..2].to_i * 60), true)
-    elsif t.size == 4
-      ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
-      hours = t[0..1].to_i
-      hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60, ambiguous)
-    elsif t.size == 5
-      Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
-    elsif t.size == 6
-      ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
-      hours = t[0..1].to_i
-      hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
-    else
-      raise("Time cannot exceed six digits")
-    end
-  end
-  
-  # 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
-  def next(pointer)
-    super
-    
-    half_day = 60 * 60 * 12
-    full_day = 60 * 60 * 24
-    
-    first = false
-    
-    unless @current_time
-      first = true
-      midnight = Time.local(@now.year, @now.month, @now.day)
-      yesterday_midnight = midnight - full_day
-      tomorrow_midnight = midnight + full_day
-
-      catch :done do
-        if pointer == :future
-          if @type.ambiguous?
-            [midnight + @type, midnight + half_day + @type, tomorrow_midnight + @type].each do |t|
-              (@current_time = t; throw :done) if t >= @now
-            end
-          else
-            [midnight + @type, tomorrow_midnight + @type].each do |t|
-              (@current_time = t; throw :done) if t >= @now
-            end
-          end
-        else # pointer == :past
-          if @type.ambiguous?
-            [midnight + half_day + @type, midnight + @type, yesterday_midnight + @type * 2].each do |t|
-              (@current_time = t; throw :done) if t <= @now
-            end
-          else
-            [midnight + @type, yesterday_midnight + @type].each do |t|
-              (@current_time = t; throw :done) if t <= @now
-            end
-          end
-        end
-      end
-      
-      @current_time || raise("Current time cannot be nil at this point")
-    end
-    
-    unless first
-      increment = @type.ambiguous? ? half_day : full_day
-      @current_time += pointer == :future ? increment : -increment
-    end
-    
-    Chronic::Span.new(@current_time, @current_time + width)
-  end
-  
-  def this(context = :future)
-    super
-    
-    context = :future if context == :none
-    
-    self.next(context)
-  end
-  
-  def width
-    1
-  end
-  
-  def to_s
-    super << '-time-' << @type.to_s
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Week.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Week.php
deleted file mode 100644 (file)
index ec88ff1..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-class Chronic::RepeaterWeek < Chronic::Repeater #:nodoc:
-  WEEK_SECONDS = 604800 # (7 * 24 * 60 * 60)
-  
-  def next(pointer)
-    super
-    
-    if !@current_week_start
-      case pointer
-      when :future
-        sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
-        sunday_repeater.start = @now
-        next_sunday_span = sunday_repeater.next(:future)
-        @current_week_start = next_sunday_span.begin
-      when :past
-        sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
-        sunday_repeater.start = (@now + Chronic::RepeaterDay::DAY_SECONDS)
-        sunday_repeater.next(:past)
-        last_sunday_span = sunday_repeater.next(:past)
-        @current_week_start = last_sunday_span.begin
-      end
-    else
-      direction = pointer == :future ? 1 : -1
-      @current_week_start += direction * WEEK_SECONDS
-    end
-    
-    Chronic::Span.new(@current_week_start, @current_week_start + WEEK_SECONDS)
-  end
-  
-  def this(pointer = :future)
-    super
-    
-    case pointer
-    when :future
-      this_week_start = Time.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
-      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
-      sunday_repeater.start = @now
-      this_sunday_span = sunday_repeater.this(:future)
-      this_week_end = this_sunday_span.begin
-      Chronic::Span.new(this_week_start, this_week_end)
-    when :past
-      this_week_end = Time.local(@now.year, @now.month, @now.day, @now.hour)
-      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
-      sunday_repeater.start = @now
-      last_sunday_span = sunday_repeater.next(:past)
-      this_week_start = last_sunday_span.begin
-      Chronic::Span.new(this_week_start, this_week_end)
-    when :none
-      sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
-      sunday_repeater.start = @now
-      last_sunday_span = sunday_repeater.next(:past)
-      this_week_start = last_sunday_span.begin
-      Chronic::Span.new(this_week_start, this_week_start + WEEK_SECONDS)
-    end
-  end
-  
-  def offset(span, amount, pointer)
-    direction = pointer == :future ? 1 : -1
-    span + direction * amount * WEEK_SECONDS
-  end
-  
-  def width
-    WEEK_SECONDS
-  end
-  
-  def to_s
-    super << '-week'
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Weekend.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Weekend.php
deleted file mode 100644 (file)
index f012267..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-class Chronic::RepeaterWeekend < Chronic::Repeater #:nodoc:
-  WEEKEND_SECONDS = 172_800 # (2 * 24 * 60 * 60)
-  
-  def next(pointer)
-    super
-    
-    if !@current_week_start
-      case pointer
-      when :future
-        saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
-        saturday_repeater.start = @now
-        next_saturday_span = saturday_repeater.next(:future)
-        @current_week_start = next_saturday_span.begin
-      when :past
-        saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
-        saturday_repeater.start = (@now + Chronic::RepeaterDay::DAY_SECONDS)
-        last_saturday_span = saturday_repeater.next(:past)
-        @current_week_start = last_saturday_span.begin
-      end
-    else
-      direction = pointer == :future ? 1 : -1
-      @current_week_start += direction * Chronic::RepeaterWeek::WEEK_SECONDS
-    end
-    
-    Chronic::Span.new(@current_week_start, @current_week_start + WEEKEND_SECONDS)
-  end
-  
-  def this(pointer = :future)
-    super
-    
-    case pointer
-    when :future, :none
-      saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
-      saturday_repeater.start = @now
-      this_saturday_span = saturday_repeater.this(:future)
-      Chronic::Span.new(this_saturday_span.begin, this_saturday_span.begin + WEEKEND_SECONDS)
-    when :past
-      saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
-      saturday_repeater.start = @now
-      last_saturday_span = saturday_repeater.this(:past)
-      Chronic::Span.new(last_saturday_span.begin, last_saturday_span.begin + WEEKEND_SECONDS)
-    end
-  end
-  
-  def offset(span, amount, pointer)
-    direction = pointer == :future ? 1 : -1
-    weekend = Chronic::RepeaterWeekend.new(:weekend)
-    weekend.start = span.begin
-    start = weekend.next(pointer).begin + (amount - 1) * direction * Chronic::RepeaterWeek::WEEK_SECONDS
-    Chronic::Span.new(start, start + (span.end - span.begin))
-  end
-  
-  def width
-    WEEKEND_SECONDS
-  end
-  
-  def to_s
-    super << '-weekend'
-  end
-end
\ No newline at end of file
diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Year.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeaters/Year.php
deleted file mode 100644 (file)
index 426371f..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-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