File: test_repeater_year.rb

package info (click to toggle)
ruby-chronic 0.10.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 492 kB
  • sloc: ruby: 4,557; makefile: 9; sh: 8
file content (69 lines) | stat: -rw-r--r-- 2,098 bytes parent folder | download | duplicates (4)
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
66
67
68
69
require 'helper'

class TestRepeaterYear < 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

    now = Time.local(2008, 2, 29)
    span = Chronic::Span.new(now, now + 1)
    offset_span = Chronic::RepeaterYear.new(:year).offset(span, 1, :past)

    assert_equal Time.local(2007, 2, 28), offset_span.begin
    assert_equal Time.local(2007, 2, 28, 0, 0, 1), offset_span.end
  end

end