public
Fork of mojombo/chronic
Description: Chronic is a pure Ruby natural language date parser.
Homepage: http://chronic.rubyforge.org
Clone URL: git://github.com/technoweenie/chronic.git
chronic / test / test_RepeaterHour.rb
100644 65 lines (47 sloc) 2.014 kb
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
54
55
56
57
58
59
60
61
62
63
64
65
require 'chronic'
require 'test/unit'
 
class TestRepeaterHour < Test::Unit::TestCase
  
  def setup
    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
  end
 
  def test_next_future
    hours = Chronic::RepeaterHour.new(:hour)
    hours.start = @now
    
    next_hour = hours.next(:future)
    assert_equal Time.local(2006, 8, 16, 15), next_hour.begin
    assert_equal Time.local(2006, 8, 16, 16), next_hour.end
    
    next_next_hour = hours.next(:future)
    assert_equal Time.local(2006, 8, 16, 16), next_next_hour.begin
    assert_equal Time.local(2006, 8, 16, 17), next_next_hour.end
  end
  
  def test_next_past
    hours = Chronic::RepeaterHour.new(:hour)
    hours.start = @now
    
    past_hour = hours.next(:past)
    assert_equal Time.local(2006, 8, 16, 13), past_hour.begin
    assert_equal Time.local(2006, 8, 16, 14), past_hour.end
    
    past_past_hour = hours.next(:past)
    assert_equal Time.local(2006, 8, 16, 12), past_past_hour.begin
    assert_equal Time.local(2006, 8, 16, 13), past_past_hour.end
  end
  
  def test_this
    @now = Time.local(2006, 8, 16, 14, 30)
    
    hours = Chronic::RepeaterHour.new(:hour)
    hours.start = @now
    
    this_hour = hours.this(:future)
    assert_equal Time.local(2006, 8, 16, 14, 31), this_hour.begin
    assert_equal Time.local(2006, 8, 16, 15), this_hour.end
    
    this_hour = hours.this(:past)
    assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
    assert_equal Time.local(2006, 8, 16, 14, 30), this_hour.end
  end
  
  def test_offset
    span = Chronic::Span.new(@now, @now + 1)
    
    offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 3, :future)
    
    assert_equal Time.local(2006, 8, 16, 17), offset_span.begin
    assert_equal Time.local(2006, 8, 16, 17, 0, 1), offset_span.end
    
    offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 24, :past)
    
    assert_equal Time.local(2006, 8, 15, 14), offset_span.begin
    assert_equal Time.local(2006, 8, 15, 14, 0, 1), offset_span.end
  end
  
end