class Chronic::RepeaterSeason
:nodoc:
def construct_season(start, finish)
def construct_season(start, finish) Span.new( Chronic.construct(start.year, start.month, start.day), Chronic.construct(finish.year, finish.month, finish.day) ) end
def find_current_season(md)
def find_current_season(md) [:spring, :summer, :autumn, :winter].find do |season| 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) unless @next_season_start || @next_season_end @next_season_start = Chronic.construct(@now.year, @now.month, @now.day) @next_season_end = Chronic.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) construct_season(@next_season_start, @next_season_end) end
def initialize(type, options = {})
def initialize(type, options = {}) super @next_season_start = nil @next_season_end = nil end
def next(pointer)
def next(pointer) super direction = pointer == :future ? 1 : -1 next_season = Season.find_next_season(find_current_season(MiniDate.from_time(@now)), direction) find_next_season_span(direction, next_season) end
def num_seconds_til(goal, direction)
def num_seconds_til(goal, direction) start = Chronic.construct(@now.year, @now.month, @now.day) seconds = 0 until MiniDate.from_time(start + direction * seconds).equals?(goal) seconds += 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) 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 = Chronic.construct(@now.year, @now.month, @now.day) this_ssn = find_current_season(MiniDate.from_time(@now)) 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 + 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 construct_season(this_ssn_start, this_ssn_end) end
def to_s
def to_s super << '-season' end
def width
def width SEASON_SECONDS end