Class: Chronic::RepeaterSeasonName

Inherits:
RepeaterSeason show all
Defined in:
lib/chronic/repeaters/repeater_season_name.rb

Overview

:nodoc:

Constant Summary collapse

SEASON_SECONDS =

91 * 24 * 60 * 60

7_862_400
DAY_SECONDS =

(24 * 60 * 60)

86_400

Constants inherited from RepeaterSeason

Chronic::RepeaterSeason::SEASONS, Chronic::RepeaterSeason::YEAR_SEASONS

Instance Attribute Summary

Attributes inherited from Tag

#type

Instance Method Summary collapse

Methods inherited from RepeaterSeason

#initialize, #to_s, #width

Methods inherited from Repeater

#<=>, scan, scan_for_day_names, scan_for_day_portions, scan_for_month_names, scan_for_season_names, scan_for_times, scan_for_units, #to_s, #width

Methods inherited from Tag

#initialize, #start=

Constructor Details

This class inherits a constructor from Chronic::RepeaterSeason

Instance Method Details

#next(pointer) ⇒ Object



7
8
9
10
# File 'lib/chronic/repeaters/repeater_season_name.rb', line 7

def next(pointer)
  direction = pointer == :future ? 1 : -1
  find_next_season_span(direction, @type)
end

#offset(span, amount, pointer) ⇒ Object



36
37
38
# File 'lib/chronic/repeaters/repeater_season_name.rb', line 36

def offset(span, amount, pointer)
  Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
end

#offset_by(time, amount, pointer) ⇒ Object



40
41
42
43
# File 'lib/chronic/repeaters/repeater_season_name.rb', line 40

def offset_by(time, amount, pointer) 
  direction = pointer == :future ? 1 : -1
  time + amount * direction * Chronic::RepeaterYear::YEAR_SECONDS
end

#this(pointer = :future) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chronic/repeaters/repeater_season_name.rb', line 12

def this(pointer = :future)
  # super
  
  direction = pointer == :future ? 1 : -1

  today = Time.construct(@now.year, @now.month, @now.day)
  goal_ssn_start = today + direction * num_seconds_til_start(@type, direction)
  goal_ssn_end = today + direction * num_seconds_til_end(@type, direction)
  curr_ssn = find_current_season(@now.to_minidate)
  case pointer
  when :past
    this_ssn_start = goal_ssn_start
    this_ssn_end = (curr_ssn == @type) ? today : goal_ssn_end
  when :future
    this_ssn_start = (curr_ssn == @type) ? today + Chronic::RepeaterDay::DAY_SECONDS : goal_ssn_start
    this_ssn_end = goal_ssn_end
  when :none
    this_ssn_start = goal_ssn_start
    this_ssn_end = goal_ssn_end
  end
  
  Chronic::Span.new(this_ssn_start, this_ssn_end)
end