Method: Chronik::RepeaterFortnight#next

Defined in:
lib/chronik/repeaters/repeater_fortnight.rb

#next(pointer) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chronik/repeaters/repeater_fortnight.rb', line 9

def next(pointer)
  super
  
  if !@current_fortnight_start
    case pointer
    when :future
      sunday_repeater = Chronik::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 = Chronik::RepeaterDayName.new(:sunday)
      sunday_repeater.start = (@now + Chronik::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
  
  Chronik::Span.new(@current_fortnight_start, @current_fortnight_start + FORTNIGHT_SECONDS)
end