Sha256: 7e75f7788016feaf5b79d30d8d7ae4c94f19090e28becea05127c42e2aca18cc

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

require File.join(File.dirname(__FILE__), *%w[helper])

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

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
slaxor-chronic-0.3.1 test/test_RepeaterHour.rb
chronic-0.3.0 test/test_RepeaterHour.rb