1 class Chronic::RepeaterDayPortion < Chronic::Repeater #:nodoc:
2 @@morning = (6 * 60 * 60)..(12 * 60 * 60) # 6am-12am
3 @@afternoon = (13 * 60 * 60)..(17 * 60 * 60) # 1pm-5pm
4 @@evening = (17 * 60 * 60)..(20 * 60 * 60) # 5pm-8pm
5 @@night = (20 * 60 * 60)..(24 * 60 * 60) # 8pm-12pm
10 if type.kind_of? Integer
11 @range = (@type * 60 * 60)..((@type + 12) * 60 * 60)
13 lookup = {:am => 1..(12 * 60 * 60),
14 :pm => (12 * 60 * 60)..(24 * 60 * 60),
15 :morning => @@morning,
16 :afternoon => @@afternoon,
17 :evening => @@evening,
20 lookup[type] || raise("Invalid type '#{type}' for RepeaterDayPortion")
22 @range || raise("Range should have been set by now")
28 full_day = 60 * 60 * 24
31 now_seconds = @now - Time.construct(@now.year, @now.month, @now.day)
32 if now_seconds < @range.begin
35 range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
37 range_start = Time.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
39 elsif now_seconds > @range.end
42 range_start = Time.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
44 range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
49 range_start = Time.construct(@now.year, @now.month, @now.day) + full_day + @range.begin
51 range_start = Time.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
55 @current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
59 @current_span += full_day
61 @current_span -= full_day
66 def this(context = :future)
69 range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
70 @current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
73 def offset(span, amount, pointer)
75 portion_span = self.next(pointer)
76 direction = pointer == :future ? 1 : -1
77 portion_span + (direction * (amount - 1) * Chronic::RepeaterDay::DAY_SECONDS)
81 @range || raise("Range has not been set")
82 return @current_span.width if @current_span
83 if @type.kind_of? Integer
86 @range.end - @range.begin
91 super << '-dayportion-' << @type.to_s