class Chronic::RepeaterSeason
:nodoc:
def find_current_season(md)
def find_current_season(md) [:spring, :summer, :autumn, :winter].each do |season| return season if md.is_between?(SEASONS[season].start, SEASONS[season].end) end end
def find_next_season_span(direction, next_season)
def find_next_season_span(direction, next_season) if !@next_season_start or !@next_season_end @next_season_start = Time.construct(@now.year, @now.month, @now.day) @next_season_end = Time.construct(@now.year, @now.month, @now.day) end @next_season_start += direction * num_seconds_til_start(next_season, direction) @next_season_end += direction * num_seconds_til_end(next_season, direction) Chronic::Span.new(@next_season_start, @next_season_end) end
def initialize(type)
def initialize(type) super @next_season_start = nil end
def next(pointer)
def next(pointer) super direction = pointer == :future ? 1 : -1 next_season = Season.find_next_season(find_current_season(@now.to_minidate), direction) find_next_season_span(direction, next_season) end
def num_seconds_til(goal, direction)
def num_seconds_til(goal, direction) start = Time.construct(@now.year, @now.month, @now.day) seconds = 0 until (start + direction * seconds).to_minidate.equals?(goal) seconds += Chronic::RepeaterDay::DAY_SECONDS end seconds end
def num_seconds_til_end(season_symbol, direction)
def num_seconds_til_end(season_symbol, direction) num_seconds_til(SEASONS[season_symbol].end, direction) end
def num_seconds_til_start(season_symbol, direction)
def num_seconds_til_start(season_symbol, direction) num_seconds_til(SEASONS[season_symbol].start, direction) end
def offset(span, amount, pointer)
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)
def offset_by(time, amount, pointer) direction = pointer == :future ? 1 : -1 time + amount * direction * SEASON_SECONDS end
def this(pointer = :future)
def this(pointer = :future) super direction = pointer == :future ? 1 : -1 today = Time.construct(@now.year, @now.month, @now.day) this_ssn = find_current_season(@now.to_minidate) case pointer when :past this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction) this_ssn_end = today when :future this_ssn_start = today + Chronic::RepeaterDay::DAY_SECONDS this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction) when :none this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction) this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction) end Chronic::Span.new(this_ssn_start, this_ssn_end) end
def to_s
def to_s super << '-season' end
def width
def width SEASON_SECONDS end