Sha256: d91d6583a50051d3fb77803afa785e61b8c89c37ec03c3e40f7edfe3a6c2567d

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

require 'chronic'
require 'test/unit'

class TestRepeaterDayName < Test::Unit::TestCase
  
  def setup
    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
  end
  
  def test_match
    token = Chronic::Token.new('saturday')
    repeater = Chronic::Repeater.scan_for_day_names(token)
    assert_equal Chronic::RepeaterDayName, repeater.class
    assert_equal :saturday, repeater.type
    
    token = Chronic::Token.new('sunday')
    repeater = Chronic::Repeater.scan_for_day_names(token)
    assert_equal Chronic::RepeaterDayName, repeater.class
    assert_equal :sunday, repeater.type
  end

  def test_next_future
    mondays = Chronic::RepeaterDayName.new(:monday)
    mondays.start = @now
    
    span = mondays.next(:future)
    
    assert_equal Time.local(2006, 8, 21), span.begin
    assert_equal Time.local(2006, 8, 22), span.end 

    span = mondays.next(:future)
    
    assert_equal Time.local(2006, 8, 28), span.begin
    assert_equal Time.local(2006, 8, 29), span.end
  end
  
  def test_next_past
    mondays = Chronic::RepeaterDayName.new(:monday)
    mondays.start = @now
    
    span = mondays.next(:past)
    
    assert_equal Time.local(2006, 8, 14), span.begin
    assert_equal Time.local(2006, 8, 15), span.end 

    span = mondays.next(:past)
    
    assert_equal Time.local(2006, 8, 7), span.begin
    assert_equal Time.local(2006, 8, 8), span.end
  end
  
  def test_next_past_across_dst_boundary
    @now = Time.local(2009, 3, 10, 0, 0, 0, 0)
    wednesdays = Chronic::RepeaterDayName.new(:wednesday)
    wednesdays.start = @now
    
    span = wednesdays.next(:past)
    
    assert_equal Time.local(2009, 3, 4), span.begin
    assert_equal Time.local(2009, 3, 5), span.end 

    span = wednesdays.next(:past)
    
    assert_equal Time.local(2009, 2, 25), span.begin
    assert_equal Time.local(2009, 2, 26), span.end    
  end
  
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jdl-chronic-0.3.0.2 test/test_RepeaterDayName.rb