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_RepeaterMonth.rb
100644 47 lines (32 sloc) 1.342 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
require 'chronic'
require 'test/unit'
 
class TestRepeaterMonth < Test::Unit::TestCase
  
  def setup
    # Wed Aug 16 14:00:00 2006
    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
  end
  
  def test_offset_by
    # future
    
    time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :future)
    assert_equal Time.local(2006, 9, 16, 14), time
    
    time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 5, :future)
    assert_equal Time.local(2007, 1, 16, 14), time
    
    # past
    
    time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :past)
    assert_equal Time.local(2006, 7, 16, 14), time
    
    time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 10, :past)
    assert_equal Time.local(2005, 10, 16, 14), time
  end
  
  def test_offset
    # future
    
    span = Chronic::Span.new(@now, @now + 60)
    offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :future)
    
    assert_equal Time.local(2006, 9, 16, 14), offset_span.begin
    assert_equal Time.local(2006, 9, 16, 14, 1), offset_span.end
    
   # past
   
   span = Chronic::Span.new(@now, @now + 60)
   offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :past)
   
   assert_equal Time.local(2006, 7, 16, 14), offset_span.begin
   assert_equal Time.local(2006, 7, 16, 14, 1), offset_span.end
  end
  
end