Sha256: 472fd7d3e9cfff3eec52163163421934b722f90385a07c1740bdeb4ff1379cfb

Contents?: true

Size: 1.86 KB

Versions: 28

Compression:

Stored size: 1.86 KB

Contents

require 'chronic'
require 'test/unit'

class TestRepeaterYear < Test::Unit::TestCase
  
  def setup
    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
  end

  def test_next_future
    years = Chronic::RepeaterYear.new(:year)
    years.start = @now
    
    next_year = years.next(:future)
    assert_equal Time.local(2007, 1, 1), next_year.begin
    assert_equal Time.local(2008, 1, 1), next_year.end
    
    next_next_year = years.next(:future)
    assert_equal Time.local(2008, 1, 1), next_next_year.begin
    assert_equal Time.local(2009, 1, 1), next_next_year.end
  end
  
  def test_next_past
    years = Chronic::RepeaterYear.new(:year)
    years.start = @now
    
    last_year = years.next(:past)
    assert_equal Time.local(2005, 1, 1), last_year.begin
    assert_equal Time.local(2006, 1, 1), last_year.end
    
    last_last_year = years.next(:past)
    assert_equal Time.local(2004, 1, 1), last_last_year.begin
    assert_equal Time.local(2005, 1, 1), last_last_year.end
  end
  
  def test_this
    years = Chronic::RepeaterYear.new(:year)
    years.start = @now
    
    this_year = years.this(:future)
    assert_equal Time.local(2006, 8, 17), this_year.begin
    assert_equal Time.local(2007, 1, 1), this_year.end
    
    this_year = years.this(:past)
    assert_equal Time.local(2006, 1, 1), this_year.begin
    assert_equal Time.local(2006, 8, 16), this_year.end
  end
  
  def test_offset
    span = Chronic::Span.new(@now, @now + 1)
    
    offset_span = Chronic::RepeaterYear.new(:year).offset(span, 3, :future)
    
    assert_equal Time.local(2009, 8, 16, 14), offset_span.begin
    assert_equal Time.local(2009, 8, 16, 14, 0, 1), offset_span.end
    
    offset_span = Chronic::RepeaterYear.new(:year).offset(span, 10, :past)
    
    assert_equal Time.local(1996, 8, 16, 14), offset_span.begin
    assert_equal Time.local(1996, 8, 16, 14, 0, 1), offset_span.end
  end
  
end

Version data entries

28 entries across 28 versions & 16 rubygems

Version Path
blakechambers-chronic-0.3.0.2 test/test_RepeaterYear.rb
evaryont-chronic-0.3.0.2 test/test_RepeaterYear.rb
jdl-chronic-0.3.0.1 test/test_RepeaterYear.rb
lmarlow-chronic-0.3.0.1 test/test_RepeaterYear.rb
mojombo-chronic-0.3.0 test/test_RepeaterYear.rb
moorage-chronic-0.3.0 test/test_RepeaterYear.rb
rgm-chronic-0.3.1 test/test_RepeaterYear.rb
sethwalker-chronic-0.3.0 test/test_RepeaterYear.rb
jdl-chronic-0.3.0.2 test/test_RepeaterYear.rb
hank-chronic-0.3.12 test/test_RepeaterYear.rb
pangel-chronic-0.3.11 test/test_RepeaterYear.rb
pangel-chronic-0.3.10 test/test_RepeaterYear.rb
aaronh-chronic-0.3.9 test/test_RepeaterYear.rb
philrosenstein-chronic-0.3.9 test/test_RepeaterYear.rb
clio-chronic-0.3.9 test/test_RepeaterYear.rb
caleb-chronic-0.3.0 test/test_RepeaterYear.rb
pyrat-chronic-0.3.1 test/test_RepeaterYear.rb
chronic-0.1.0 test/test_RepeaterYear.rb
chronic-0.1.1 test/test_RepeaterYear.rb
chronic-0.1.3 test/test_RepeaterYear.rb