1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
module Chronic
class RepeaterDay < Repeater #:nodoc:
DAY_SECONDS = 86_400 # (24 * 60 * 60)
def initialize(type)
super
end
def next(pointer)
super
if !@current_day_start
@current_day_start = Chronic.time_class.local(@now.year, @now.month, @now.day)
end
direction = pointer == :future ? 1 : -1
@current_day_start += direction * DAY_SECONDS
Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
end
def this(pointer = :future)
super
case pointer
when :future
day_begin = Chronic.construct(@now.year, @now.month, @now.day, @now.hour)
day_end = Chronic.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
when :past
day_begin = Chronic.construct(@now.year, @now.month, @now.day)
day_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour)
when :none
day_begin = Chronic.construct(@now.year, @now.month, @now.day)
day_end = Chronic.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
end
Span.new(day_begin, day_end)
end
def offset(span, amount, pointer)
direction = pointer == :future ? 1 : -1
span + direction * amount * DAY_SECONDS
end
def width
DAY_SECONDS
end
def to_s
super << '-day'
end
end
end
|