Merge branch 'gem'
[fuzed.git] / helloworld / vendor / gems / chronic-0.2.2 / lib / chronic / repeaters / repeater_day.rb
bloba92d83f63fe2de69aaea31bbe7c4dcde6dac8783
1 class Chronic::RepeaterDay < Chronic::Repeater #:nodoc:
2   DAY_SECONDS = 86_400 # (24 * 60 * 60)
3   
4   def next(pointer)
5     super
6     
7     if !@current_day_start
8       @current_day_start = Time.local(@now.year, @now.month, @now.day)
9     end
10     
11     direction = pointer == :future ? 1 : -1
12     @current_day_start += direction * DAY_SECONDS
13     
14     Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
15   end
16   
17   def this(pointer = :future)
18     super
19     
20     case pointer
21     when :future
22       day_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour + 1)
23       day_end = Time.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
24     when :past
25       day_begin = Time.construct(@now.year, @now.month, @now.day)
26       day_end = Time.construct(@now.year, @now.month, @now.day, @now.hour)
27     when :none
28       day_begin = Time.construct(@now.year, @now.month, @now.day)
29       day_end = Time.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
30     end
31     
32     Chronic::Span.new(day_begin, day_end)
33   end
34   
35   def offset(span, amount, pointer)
36     direction = pointer == :future ? 1 : -1
37     span + direction * amount * DAY_SECONDS
38   end
39   
40   def width
41     DAY_SECONDS
42   end
43   
44   def to_s
45     super << '-day'
46   end
47 end