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