0
+ MiniDate.new(self.month, self.day)
0
+ attr_reader :start, :end
0
+ def initialize(myStart, myEnd)
0
+ def self.find_next_season(season, pointer)
0
+ lookup = {:spring => 0, :summer => 1, :autumn => 2, :winter => 3}
0
+ next_season_num = (lookup[season]+1*pointer) % 4
0
+ lookup.invert[next_season_num]
0
+ def self.season_after(season); find_next_season(season, +1); end
0
+ def self.season_before(season); find_next_season(season, -1); end
0
+ attr_accessor :month, :day
0
+ def initialize(month, day)
0
+ def is_between?(md_start, md_end)
0
+ return true if (@month == md_start.month and @day >= md_start.day) ||
0
+ (@month == md_end.month and @day <= md_end.day)
0
+ i = md_start.month + 1
0
+ until i == md_end.month
0
+ return true if @month == i
0
+ @month == other.month and day == other.day
0
class Chronic::RepeaterSeason < Chronic::Repeater #:nodoc:
0
SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
0
+ SEASONS = { :spring => Season.new( MiniDate.new(3,20),MiniDate.new(6,20) ),
0
+ :summer => Season.new( MiniDate.new(6,21),MiniDate.new(9,22) ),
0
+ :autumn => Season.new( MiniDate.new(9,23),MiniDate.new(12,21) ),
0
+ :winter => Season.new( MiniDate.new(12,22),MiniDate.new(3,19) ) }
0
- raise 'Not implemented'
0
+ direction = pointer == :future ? 1 : -1
0
+ next_season = Season.find_next_season(find_current_season(@now.to_minidate), direction)
0
+ find_next_season_span(direction, next_season)
0
def this(pointer = :future)
0
- raise 'Not implemented'
0
+ direction = pointer == :future ? 1 : -1
0
+ today = Time.construct(@now.year, @now.month, @now.day)
0
+ this_ssn = find_current_season(@now.to_minidate)
0
+ this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction)
0
+ this_ssn_start = today + Chronic::RepeaterDay::DAY_SECONDS
0
+ this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction)
0
+ this_ssn_start = today + direction * num_seconds_til_start(this_ssn, direction)
0
+ this_ssn_end = today + direction * num_seconds_til_end(this_ssn, direction)
0
+ Chronic::Span.new(this_ssn_start, this_ssn_end)
0
+ def offset(span, amount, pointer)
0
+ Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
0
+ def offset_by(time, amount, pointer)
0
+ direction = pointer == :future ? 1 : -1
0
+ time + amount * direction * SEASON_SECONDS
0
@@ -20,4 +103,43 @@ class Chronic::RepeaterSeason < Chronic::Repeater #:nodoc:
0
+ def find_next_season_span(direction, next_season)
0
+ if !@next_season_start or !@next_season_end
0
+ @next_season_start = Time.construct(@now.year, @now.month, @now.day)
0
+ @next_season_end = Time.construct(@now.year, @now.month, @now.day)
0
+ @next_season_start += direction * num_seconds_til_start(next_season, direction)
0
+ @next_season_end += direction * num_seconds_til_end(next_season, direction)
0
+ Chronic::Span.new(@next_season_start, @next_season_end)
0
+ def find_current_season(md)
0
+ [:spring, :summer, :autumn, :winter].each do |season|
0
+ return season if md.is_between?(SEASONS[season].start, SEASONS[season].end)
0
+ def num_seconds_til(goal, direction)
0
+ start = Time.construct(@now.year, @now.month, @now.day)
0
+ until (start + direction * seconds).to_minidate.equals?(goal)
0
+ seconds += Chronic::RepeaterDay::DAY_SECONDS
0
+ def num_seconds_til_start(season_symbol, direction)
0
+ num_seconds_til(SEASONS[season_symbol].start, direction)
0
+ def num_seconds_til_end(season_symbol, direction)
0
+ num_seconds_til(SEASONS[season_symbol].end, direction)
0
\ No newline at end of file
Comments
No one has commented yet.