1 class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
5 def initialize(time, ambiguous = false)
15 Tick.new(@time * other, @ambiguous)
23 @time.to_s + (@ambiguous ? '?' : '')
27 def initialize(time, options = {})
28 t = time.gsub(/\:/, '')
31 Tick.new(t.to_i * 60 * 60, true)
33 Tick.new((t[0..0].to_i * 60 * 60) + (t[1..2].to_i * 60), true)
35 ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
36 Tick.new(t[0..1].to_i * 60 * 60 + t[2..3].to_i * 60, ambiguous)
38 Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
40 ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
41 Tick.new(t[0..1].to_i * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
43 raise("Time cannot exceed six digits")
47 # Return the next past or future Span for the time that this Repeater represents
48 # pointer - Symbol representing which temporal direction to fetch the next day
49 # must be either :past or :future
53 half_day = 60 * 60 * 12
54 full_day = 60 * 60 * 24
60 midnight = Time.local(@now.year, @now.month, @now.day)
61 yesterday_midnight = midnight - full_day
62 tomorrow_midnight = midnight + full_day
67 [midnight + @type, midnight + half_day + @type, tomorrow_midnight + @type].each do |t|
68 (@current_time = t; throw :done) if t > @now
71 [midnight + @type, tomorrow_midnight + @type].each do |t|
72 (@current_time = t; throw :done) if t > @now
75 else # pointer == :past
77 [midnight + half_day + @type, midnight + @type, yesterday_midnight + @type * 2].each do |t|
78 (@current_time = t; throw :done) if t < @now
81 [midnight + @type, yesterday_midnight + @type].each do |t|
82 (@current_time = t; throw :done) if t < @now
88 @current_time || raise("Current time cannot be nil at this point")
92 increment = @type.ambiguous? ? half_day : full_day
93 @current_time += pointer == :future ? increment : -increment
96 Chronic::Span.new(@current_time, @current_time + width)
99 def this(context = :future)
102 context = :future if context == :none
112 super << '-time-' << @type.to_s