chronic-mmlac 0.6.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/.gitignore +5 -0
  4. data/.yardopts +3 -0
  5. data/HISTORY.md +174 -0
  6. data/LICENSE +21 -0
  7. data/README.md +177 -0
  8. data/Rakefile +46 -0
  9. data/chronic.gemspec +17 -0
  10. data/lib/chronic/chronic.rb +325 -0
  11. data/lib/chronic/grabber.rb +31 -0
  12. data/lib/chronic/handler.rb +90 -0
  13. data/lib/chronic/handlers.rb +465 -0
  14. data/lib/chronic/mini_date.rb +38 -0
  15. data/lib/chronic/numerizer.rb +121 -0
  16. data/lib/chronic/ordinal.rb +44 -0
  17. data/lib/chronic/pointer.rb +30 -0
  18. data/lib/chronic/repeater.rb +135 -0
  19. data/lib/chronic/repeaters/repeater_day.rb +53 -0
  20. data/lib/chronic/repeaters/repeater_day_name.rb +52 -0
  21. data/lib/chronic/repeaters/repeater_day_portion.rb +94 -0
  22. data/lib/chronic/repeaters/repeater_fortnight.rb +71 -0
  23. data/lib/chronic/repeaters/repeater_hour.rb +58 -0
  24. data/lib/chronic/repeaters/repeater_minute.rb +58 -0
  25. data/lib/chronic/repeaters/repeater_month.rb +79 -0
  26. data/lib/chronic/repeaters/repeater_month_name.rb +94 -0
  27. data/lib/chronic/repeaters/repeater_season.rb +109 -0
  28. data/lib/chronic/repeaters/repeater_season_name.rb +43 -0
  29. data/lib/chronic/repeaters/repeater_second.rb +42 -0
  30. data/lib/chronic/repeaters/repeater_time.rb +128 -0
  31. data/lib/chronic/repeaters/repeater_week.rb +74 -0
  32. data/lib/chronic/repeaters/repeater_weekday.rb +85 -0
  33. data/lib/chronic/repeaters/repeater_weekend.rb +66 -0
  34. data/lib/chronic/repeaters/repeater_year.rb +77 -0
  35. data/lib/chronic/scalar.rb +109 -0
  36. data/lib/chronic/season.rb +37 -0
  37. data/lib/chronic/separator.rb +88 -0
  38. data/lib/chronic/span.rb +31 -0
  39. data/lib/chronic/tag.rb +42 -0
  40. data/lib/chronic/time_zone.rb +30 -0
  41. data/lib/chronic/token.rb +45 -0
  42. data/lib/chronic.rb +118 -0
  43. data/test/helper.rb +6 -0
  44. data/test/test_Chronic.rb +148 -0
  45. data/test/test_DaylightSavings.rb +118 -0
  46. data/test/test_Handler.rb +104 -0
  47. data/test/test_MiniDate.rb +32 -0
  48. data/test/test_Numerizer.rb +72 -0
  49. data/test/test_RepeaterDayName.rb +51 -0
  50. data/test/test_RepeaterFortnight.rb +62 -0
  51. data/test/test_RepeaterHour.rb +68 -0
  52. data/test/test_RepeaterMinute.rb +34 -0
  53. data/test/test_RepeaterMonth.rb +50 -0
  54. data/test/test_RepeaterMonthName.rb +56 -0
  55. data/test/test_RepeaterSeason.rb +40 -0
  56. data/test/test_RepeaterTime.rb +70 -0
  57. data/test/test_RepeaterWeek.rb +62 -0
  58. data/test/test_RepeaterWeekday.rb +55 -0
  59. data/test/test_RepeaterWeekend.rb +74 -0
  60. data/test/test_RepeaterYear.rb +69 -0
  61. data/test/test_Span.rb +23 -0
  62. data/test/test_Token.rb +25 -0
  63. data/test/test_parsing.rb +886 -0
  64. metadata +132 -0
@@ -0,0 +1,118 @@
1
+ require 'helper'
2
+
3
+ class TestDaylightSavings < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @begin_daylight_savings = Time.local(2008, 3, 9, 5, 0, 0, 0)
7
+ @end_daylight_savings = Time.local(2008, 11, 2, 5, 0, 0, 0)
8
+ end
9
+
10
+ def test_begin_past
11
+ # ambiguous - resolve to last night
12
+ t = Chronic::RepeaterTime.new('900')
13
+ t.start = @begin_daylight_savings
14
+ assert_equal Time.local(2008, 3, 8, 21), t.next(:past).begin
15
+
16
+ # ambiguous - resolve to this afternoon
17
+ t = Chronic::RepeaterTime.new('900')
18
+ t.start = Time.local(2008, 3, 9, 22, 0, 0, 0)
19
+ assert_equal Time.local(2008, 3, 9, 21), t.next(:past).begin
20
+
21
+ # ambiguous - resolve to this morning
22
+ t = Chronic::RepeaterTime.new('400')
23
+ t.start = @begin_daylight_savings
24
+ assert_equal Time.local(2008, 3, 9, 4), t.next(:past).begin
25
+
26
+ # unambiguous - resolve to today
27
+ t = Chronic::RepeaterTime.new('0400')
28
+ t.start = @begin_daylight_savings
29
+ assert_equal Time.local(2008, 3, 9, 4), t.next(:past).begin
30
+
31
+ # unambiguous - resolve to yesterday
32
+ t = Chronic::RepeaterTime.new('1300')
33
+ t.start = @begin_daylight_savings
34
+ assert_equal Time.local(2008, 3, 8, 13), t.next(:past).begin
35
+ end
36
+
37
+ def test_begin_future
38
+ # ambiguous - resolve to this morning
39
+ t = Chronic::RepeaterTime.new('900')
40
+ t.start = @begin_daylight_savings
41
+ assert_equal Time.local(2008, 3, 9, 9), t.next(:future).begin
42
+
43
+ # ambiguous - resolve to this afternoon
44
+ t = Chronic::RepeaterTime.new('900')
45
+ t.start = Time.local(2008, 3, 9, 13, 0, 0, 0)
46
+ assert_equal Time.local(2008, 3, 9, 21), t.next(:future).begin
47
+
48
+ # ambiguous - resolve to tomorrow
49
+ t = Chronic::RepeaterTime.new('900')
50
+ t.start = Time.local(2008, 3, 9, 22, 0, 0, 0)
51
+ assert_equal Time.local(2008, 3, 10, 9), t.next(:future).begin
52
+
53
+ # unambiguous - resolve to today
54
+ t = Chronic::RepeaterTime.new('0900')
55
+ t.start = @begin_daylight_savings
56
+ assert_equal Time.local(2008, 3, 9, 9), t.next(:future).begin
57
+
58
+ # unambiguous - resolve to tomorrow
59
+ t = Chronic::RepeaterTime.new('0400')
60
+ t.start = @begin_daylight_savings
61
+ assert_equal Time.local(2008, 3, 10, 4), t.next(:future).begin
62
+ end
63
+
64
+ def test_end_past
65
+ # ambiguous - resolve to last night
66
+ t = Chronic::RepeaterTime.new('900')
67
+ t.start = @end_daylight_savings
68
+ assert_equal Time.local(2008, 11, 1, 21), t.next(:past).begin
69
+
70
+ # ambiguous - resolve to this afternoon
71
+ t = Chronic::RepeaterTime.new('900')
72
+ t.start = Time.local(2008, 11, 2, 22, 0, 0, 0)
73
+ assert_equal Time.local(2008, 11, 2, 21), t.next(:past).begin
74
+
75
+ # ambiguous - resolve to this morning
76
+ t = Chronic::RepeaterTime.new('400')
77
+ t.start = @end_daylight_savings
78
+ assert_equal Time.local(2008, 11, 2, 4), t.next(:past).begin
79
+
80
+ # unambiguous - resolve to today
81
+ t = Chronic::RepeaterTime.new('0400')
82
+ t.start = @end_daylight_savings
83
+ assert_equal Time.local(2008, 11, 2, 4), t.next(:past).begin
84
+
85
+ # unambiguous - resolve to yesterday
86
+ t = Chronic::RepeaterTime.new('1300')
87
+ t.start = @end_daylight_savings
88
+ assert_equal Time.local(2008, 11, 1, 13), t.next(:past).begin
89
+ end
90
+
91
+ def test_end_future
92
+ # ambiguous - resolve to this morning
93
+ t = Chronic::RepeaterTime.new('900')
94
+ t.start = @end_daylight_savings
95
+ assert_equal Time.local(2008, 11, 2, 9), t.next(:future).begin
96
+
97
+ # ambiguous - resolve to this afternoon
98
+ t = Chronic::RepeaterTime.new('900')
99
+ t.start = Time.local(2008, 11, 2, 13, 0, 0, 0)
100
+ assert_equal Time.local(2008, 11, 2, 21), t.next(:future).begin
101
+
102
+ # ambiguous - resolve to tomorrow
103
+ t = Chronic::RepeaterTime.new('900')
104
+ t.start = Time.local(2008, 11, 2, 22, 0, 0, 0)
105
+ assert_equal Time.local(2008, 11, 3, 9), t.next(:future).begin
106
+
107
+ # unambiguous - resolve to today
108
+ t = Chronic::RepeaterTime.new('0900')
109
+ t.start = @end_daylight_savings
110
+ assert_equal Time.local(2008, 11, 2, 9), t.next(:future).begin
111
+
112
+ # unambiguous - resolve to tomorrow
113
+ t = Chronic::RepeaterTime.new('0400')
114
+ t.start = @end_daylight_savings
115
+ assert_equal Time.local(2008, 11, 3, 4), t.next(:future).begin
116
+ end
117
+
118
+ end
@@ -0,0 +1,104 @@
1
+ require 'helper'
2
+
3
+ class TestHandler < Test::Unit::TestCase
4
+
5
+ def setup
6
+ # Wed Aug 16 14:00:00 UTC 2006
7
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
+ end
9
+
10
+ def test_handler_class_1
11
+ handler = Chronic::Handler.new([:repeater], :handler)
12
+
13
+ tokens = [Chronic::Token.new('friday')]
14
+ tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
15
+
16
+ assert handler.match(tokens, Chronic.definitions)
17
+
18
+ tokens << Chronic::Token.new('afternoon')
19
+ tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))
20
+
21
+ assert !handler.match(tokens, Chronic.definitions)
22
+ end
23
+
24
+ def test_handler_class_2
25
+ handler = Chronic::Handler.new([:repeater, :repeater?], :handler)
26
+
27
+ tokens = [Chronic::Token.new('friday')]
28
+ tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
29
+
30
+ assert handler.match(tokens, Chronic.definitions)
31
+
32
+ tokens << Chronic::Token.new('afternoon')
33
+ tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))
34
+
35
+ assert handler.match(tokens, Chronic.definitions)
36
+
37
+ tokens << Chronic::Token.new('afternoon')
38
+ tokens[2].tag(Chronic::RepeaterDayPortion.new(:afternoon))
39
+
40
+ assert !handler.match(tokens, Chronic.definitions)
41
+ end
42
+
43
+ def test_handler_class_3
44
+ handler = Chronic::Handler.new([:repeater, 'time?'], :handler)
45
+
46
+ tokens = [Chronic::Token.new('friday')]
47
+ tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
48
+
49
+ assert handler.match(tokens, Chronic.definitions)
50
+
51
+ tokens << Chronic::Token.new('afternoon')
52
+ tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))
53
+
54
+ assert !handler.match(tokens, Chronic.definitions)
55
+ end
56
+
57
+ def test_handler_class_4
58
+ handler = Chronic::Handler.new([:repeater_month_name, :scalar_day, 'time?'], :handler)
59
+
60
+ tokens = [Chronic::Token.new('may')]
61
+ tokens[0].tag(Chronic::RepeaterMonthName.new(:may))
62
+
63
+ assert !handler.match(tokens, Chronic.definitions)
64
+
65
+ tokens << Chronic::Token.new('27')
66
+ tokens[1].tag(Chronic::ScalarDay.new(27))
67
+
68
+ assert handler.match(tokens, Chronic.definitions)
69
+ end
70
+
71
+ def test_handler_class_5
72
+ handler = Chronic::Handler.new([:repeater, 'time?'], :handler)
73
+
74
+ tokens = [Chronic::Token.new('friday')]
75
+ tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
76
+
77
+ assert handler.match(tokens, Chronic.definitions)
78
+
79
+ tokens << Chronic::Token.new('5:00')
80
+ tokens[1].tag(Chronic::RepeaterTime.new('5:00'))
81
+
82
+ assert handler.match(tokens, Chronic.definitions)
83
+
84
+ tokens << Chronic::Token.new('pm')
85
+ tokens[2].tag(Chronic::RepeaterDayPortion.new(:pm))
86
+
87
+ assert handler.match(tokens, Chronic.definitions)
88
+ end
89
+
90
+ def test_handler_class_6
91
+ handler = Chronic::Handler.new([:scalar, :repeater, :pointer], :handler)
92
+
93
+ tokens = [Chronic::Token.new('3'),
94
+ Chronic::Token.new('years'),
95
+ Chronic::Token.new('past')]
96
+
97
+ tokens[0].tag(Chronic::Scalar.new(3))
98
+ tokens[1].tag(Chronic::RepeaterYear.new(:year))
99
+ tokens[2].tag(Chronic::Pointer.new(:past))
100
+
101
+ assert handler.match(tokens, Chronic.definitions)
102
+ end
103
+
104
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ class TestMiniDate < Test::Unit::TestCase
4
+ def test_valid_month
5
+ assert_raise(ArgumentError){ Chronic::MiniDate.new(0,12) }
6
+ assert_raise(ArgumentError){ Chronic::MiniDate.new(13,1) }
7
+ end
8
+
9
+ def test_is_between
10
+ m=Chronic::MiniDate.new(3,2)
11
+ assert m.is_between?(Chronic::MiniDate.new(2,4), Chronic::MiniDate.new(4,7))
12
+ assert !m.is_between?(Chronic::MiniDate.new(1,5), Chronic::MiniDate.new(2,7))
13
+
14
+ #There was a hang if date tested is in december and outside the testing range
15
+ m=Chronic::MiniDate.new(12,24)
16
+ assert !m.is_between?(Chronic::MiniDate.new(10,1), Chronic::MiniDate.new(12,21))
17
+ end
18
+
19
+ def test_is_between_short_range
20
+ m=Chronic::MiniDate.new(5,10)
21
+ assert m.is_between?(Chronic::MiniDate.new(5,3), Chronic::MiniDate.new(5,12))
22
+ assert !m.is_between?(Chronic::MiniDate.new(5,11), Chronic::MiniDate.new(5,15))
23
+ end
24
+
25
+ def test_is_between_wrapping_range
26
+ m=Chronic::MiniDate.new(1,1)
27
+ assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(2,2))
28
+ m=Chronic::MiniDate.new(12,12)
29
+ assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(1,5))
30
+ end
31
+
32
+ end
@@ -0,0 +1,72 @@
1
+ require 'helper'
2
+
3
+ class ParseNumbersTest < Test::Unit::TestCase
4
+
5
+ def test_straight_parsing
6
+ strings = {
7
+ 'one' => 1,
8
+ 'five' => 5,
9
+ 'ten' => 10,
10
+ 'eleven' => 11,
11
+ 'twelve' => 12,
12
+ 'thirteen' => 13,
13
+ 'fourteen' => 14,
14
+ 'fifteen' => 15,
15
+ 'sixteen' => 16,
16
+ 'seventeen' => 17,
17
+ 'eighteen' => 18,
18
+ 'nineteen' => 19,
19
+ 'twenty' => 20,
20
+ 'twenty seven' => 27,
21
+ 'thirty-one' => 31,
22
+ 'thirty-seven' => 37,
23
+ 'thirty seven' => 37,
24
+ 'fifty nine' => 59,
25
+ 'forty two' => 42,
26
+ 'fourty two' => 42,
27
+ # 'a hundred' => 100,
28
+ 'one hundred' => 100,
29
+ 'one hundred and fifty' => 150,
30
+ # 'one fifty' => 150,
31
+ 'two-hundred' => 200,
32
+ '5 hundred' => 500,
33
+ 'nine hundred and ninety nine' => 999,
34
+ 'one thousand' => 1000,
35
+ 'twelve hundred' => 1200,
36
+ 'one thousand two hundred' => 1_200,
37
+ 'seventeen thousand' => 17_000,
38
+ 'twentyone-thousand-four-hundred-and-seventy-three' => 21_473,
39
+ 'seventy four thousand and two' => 74_002,
40
+ 'ninety nine thousand nine hundred ninety nine' => 99_999,
41
+ '100 thousand' => 100_000,
42
+ 'two hundred fifty thousand' => 250_000,
43
+ 'one million' => 1_000_000,
44
+ 'one million two hundred fifty thousand and seven' => 1_250_007,
45
+ 'one billion' => 1_000_000_000,
46
+ 'one billion and one' => 1_000_000_001}
47
+
48
+ strings.each do |key, val|
49
+ assert_equal val, Chronic::Numerizer.numerize(key).to_i
50
+ end
51
+ end
52
+
53
+ def test_ordinal_strings
54
+ {
55
+ 'first' => '1st',
56
+ 'second' => 'second',
57
+ 'second day' => '2nd day',
58
+ 'second of may' => '2nd of may',
59
+ 'fifth' => '5th',
60
+ 'twenty third' => '23rd',
61
+ 'first day month two' => '1st day month 2'
62
+ }.each do |key, val|
63
+ # Use pre_normalize here instead of Numerizer directly because
64
+ # pre_normalize deals with parsing 'second' appropriately
65
+ assert_equal val, Chronic.pre_normalize(key)
66
+ end
67
+ end
68
+
69
+ def test_edges
70
+ assert_equal "27 Oct 2006 7:30am", Chronic::Numerizer.numerize("27 Oct 2006 7:30am")
71
+ end
72
+ end
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterDayName < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
7
+ end
8
+
9
+ def test_match
10
+ token = Chronic::Token.new('saturday')
11
+ repeater = Chronic::Repeater.scan_for_day_names(token)
12
+ assert_equal Chronic::RepeaterDayName, repeater.class
13
+ assert_equal :saturday, repeater.type
14
+
15
+ token = Chronic::Token.new('sunday')
16
+ repeater = Chronic::Repeater.scan_for_day_names(token)
17
+ assert_equal Chronic::RepeaterDayName, repeater.class
18
+ assert_equal :sunday, repeater.type
19
+ end
20
+
21
+ def test_next_future
22
+ mondays = Chronic::RepeaterDayName.new(:monday)
23
+ mondays.start = @now
24
+
25
+ span = mondays.next(:future)
26
+
27
+ assert_equal Time.local(2006, 8, 21), span.begin
28
+ assert_equal Time.local(2006, 8, 22), span.end
29
+
30
+ span = mondays.next(:future)
31
+
32
+ assert_equal Time.local(2006, 8, 28), span.begin
33
+ assert_equal Time.local(2006, 8, 29), span.end
34
+ end
35
+
36
+ def test_next_past
37
+ mondays = Chronic::RepeaterDayName.new(:monday)
38
+ mondays.start = @now
39
+
40
+ span = mondays.next(:past)
41
+
42
+ assert_equal Time.local(2006, 8, 14), span.begin
43
+ assert_equal Time.local(2006, 8, 15), span.end
44
+
45
+ span = mondays.next(:past)
46
+
47
+ assert_equal Time.local(2006, 8, 7), span.begin
48
+ assert_equal Time.local(2006, 8, 8), span.end
49
+ end
50
+
51
+ end
@@ -0,0 +1,62 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterFortnight < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
7
+ end
8
+
9
+ def test_next_future
10
+ fortnights = Chronic::RepeaterFortnight.new(:fortnight)
11
+ fortnights.start = @now
12
+
13
+ next_fortnight = fortnights.next(:future)
14
+ assert_equal Time.local(2006, 8, 20), next_fortnight.begin
15
+ assert_equal Time.local(2006, 9, 3), next_fortnight.end
16
+
17
+ next_next_fortnight = fortnights.next(:future)
18
+ assert_equal Time.local(2006, 9, 3), next_next_fortnight.begin
19
+ assert_equal Time.local(2006, 9, 17), next_next_fortnight.end
20
+ end
21
+
22
+ def test_next_past
23
+ fortnights = Chronic::RepeaterFortnight.new(:fortnight)
24
+ fortnights.start = @now
25
+
26
+ last_fortnight = fortnights.next(:past)
27
+ assert_equal Time.local(2006, 7, 30), last_fortnight.begin
28
+ assert_equal Time.local(2006, 8, 13), last_fortnight.end
29
+
30
+ last_last_fortnight = fortnights.next(:past)
31
+ assert_equal Time.local(2006, 7, 16), last_last_fortnight.begin
32
+ assert_equal Time.local(2006, 7, 30), last_last_fortnight.end
33
+ end
34
+
35
+ def test_this_future
36
+ fortnights = Chronic::RepeaterFortnight.new(:fortnight)
37
+ fortnights.start = @now
38
+
39
+ this_fortnight = fortnights.this(:future)
40
+ assert_equal Time.local(2006, 8, 16, 15), this_fortnight.begin
41
+ assert_equal Time.local(2006, 8, 27), this_fortnight.end
42
+ end
43
+
44
+ def test_this_past
45
+ fortnights = Chronic::RepeaterFortnight.new(:fortnight)
46
+ fortnights.start = @now
47
+
48
+ this_fortnight = fortnights.this(:past)
49
+ assert_equal Time.local(2006, 8, 13, 0), this_fortnight.begin
50
+ assert_equal Time.local(2006, 8, 16, 14), this_fortnight.end
51
+ end
52
+
53
+ def test_offset
54
+ span = Chronic::Span.new(@now, @now + 1)
55
+
56
+ offset_span = Chronic::RepeaterWeek.new(:week).offset(span, 3, :future)
57
+
58
+ assert_equal Time.local(2006, 9, 6, 14), offset_span.begin
59
+ assert_equal Time.local(2006, 9, 6, 14, 0, 1), offset_span.end
60
+ end
61
+
62
+ end
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterHour < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
7
+ end
8
+
9
+ def test_next_future
10
+ hours = Chronic::RepeaterHour.new(:hour)
11
+ hours.start = @now
12
+
13
+ next_hour = hours.next(:future)
14
+ assert_equal Time.local(2006, 8, 16, 15), next_hour.begin
15
+ assert_equal Time.local(2006, 8, 16, 16), next_hour.end
16
+
17
+ next_next_hour = hours.next(:future)
18
+ assert_equal Time.local(2006, 8, 16, 16), next_next_hour.begin
19
+ assert_equal Time.local(2006, 8, 16, 17), next_next_hour.end
20
+ end
21
+
22
+ def test_next_past
23
+ hours = Chronic::RepeaterHour.new(:hour)
24
+ hours.start = @now
25
+
26
+ past_hour = hours.next(:past)
27
+ assert_equal Time.local(2006, 8, 16, 13), past_hour.begin
28
+ assert_equal Time.local(2006, 8, 16, 14), past_hour.end
29
+
30
+ past_past_hour = hours.next(:past)
31
+ assert_equal Time.local(2006, 8, 16, 12), past_past_hour.begin
32
+ assert_equal Time.local(2006, 8, 16, 13), past_past_hour.end
33
+ end
34
+
35
+ def test_this
36
+ @now = Time.local(2006, 8, 16, 14, 30)
37
+
38
+ hours = Chronic::RepeaterHour.new(:hour)
39
+ hours.start = @now
40
+
41
+ this_hour = hours.this(:future)
42
+ assert_equal Time.local(2006, 8, 16, 14, 31), this_hour.begin
43
+ assert_equal Time.local(2006, 8, 16, 15), this_hour.end
44
+
45
+ this_hour = hours.this(:past)
46
+ assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
47
+ assert_equal Time.local(2006, 8, 16, 14, 30), this_hour.end
48
+
49
+ this_hour = hours.this(:none)
50
+ assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
51
+ assert_equal Time.local(2006, 8, 16, 15), this_hour.end
52
+ end
53
+
54
+ def test_offset
55
+ span = Chronic::Span.new(@now, @now + 1)
56
+
57
+ offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 3, :future)
58
+
59
+ assert_equal Time.local(2006, 8, 16, 17), offset_span.begin
60
+ assert_equal Time.local(2006, 8, 16, 17, 0, 1), offset_span.end
61
+
62
+ offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 24, :past)
63
+
64
+ assert_equal Time.local(2006, 8, 15, 14), offset_span.begin
65
+ assert_equal Time.local(2006, 8, 15, 14, 0, 1), offset_span.end
66
+ end
67
+
68
+ end
@@ -0,0 +1,34 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterMinute < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2008, 6, 25, 7, 15, 30, 0)
7
+ end
8
+
9
+ def test_next_future
10
+ minutes = Chronic::RepeaterMinute.new(:minute)
11
+ minutes.start = @now
12
+
13
+ next_minute = minutes.next(:future)
14
+ assert_equal Time.local(2008, 6, 25, 7, 16), next_minute.begin
15
+ assert_equal Time.local(2008, 6, 25, 7, 17), next_minute.end
16
+
17
+ next_next_minute = minutes.next(:future)
18
+ assert_equal Time.local(2008, 6, 25, 7, 17), next_next_minute.begin
19
+ assert_equal Time.local(2008, 6, 25, 7, 18), next_next_minute.end
20
+ end
21
+
22
+ def test_next_past
23
+ minutes = Chronic::RepeaterMinute.new(:minute)
24
+ minutes.start = @now
25
+
26
+ prev_minute = minutes.next(:past)
27
+ assert_equal Time.local(2008, 6, 25, 7, 14), prev_minute.begin
28
+ assert_equal Time.local(2008, 6, 25, 7, 15), prev_minute.end
29
+
30
+ prev_prev_minute = minutes.next(:past)
31
+ assert_equal Time.local(2008, 6, 25, 7, 13), prev_prev_minute.begin
32
+ assert_equal Time.local(2008, 6, 25, 7, 14), prev_prev_minute.end
33
+ end
34
+ end
@@ -0,0 +1,50 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterMonth < Test::Unit::TestCase
4
+
5
+ def setup
6
+ # Wed Aug 16 14:00:00 2006
7
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
+ end
9
+
10
+ def test_offset_by
11
+ # future
12
+
13
+ time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :future)
14
+ assert_equal Time.local(2006, 9, 16, 14), time
15
+
16
+ time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 5, :future)
17
+ assert_equal Time.local(2007, 1, 16, 14), time
18
+
19
+ # past
20
+
21
+ time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :past)
22
+ assert_equal Time.local(2006, 7, 16, 14), time
23
+
24
+ time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 10, :past)
25
+ assert_equal Time.local(2005, 10, 16, 14), time
26
+
27
+ time = Chronic::RepeaterMonth.new(:month).offset_by(Time.local(2010, 3, 29), 1, :past)
28
+ assert_equal 2, time.month
29
+ assert_equal 28, time.day
30
+ end
31
+
32
+ def test_offset
33
+ # future
34
+
35
+ span = Chronic::Span.new(@now, @now + 60)
36
+ offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :future)
37
+
38
+ assert_equal Time.local(2006, 9, 16, 14), offset_span.begin
39
+ assert_equal Time.local(2006, 9, 16, 14, 1), offset_span.end
40
+
41
+ # past
42
+
43
+ span = Chronic::Span.new(@now, @now + 60)
44
+ offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :past)
45
+
46
+ assert_equal Time.local(2006, 7, 16, 14), offset_span.begin
47
+ assert_equal Time.local(2006, 7, 16, 14, 1), offset_span.end
48
+ end
49
+
50
+ end
@@ -0,0 +1,56 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterMonthName < Test::Unit::TestCase
4
+
5
+ def setup
6
+ # Wed Aug 16 14:00:00 2006
7
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
8
+ end
9
+
10
+ def test_next
11
+ # future
12
+
13
+ mays = Chronic::RepeaterMonthName.new(:may)
14
+ mays.start = @now
15
+
16
+ next_may = mays.next(:future)
17
+ assert_equal Time.local(2007, 5), next_may.begin
18
+ assert_equal Time.local(2007, 6), next_may.end
19
+
20
+ next_next_may = mays.next(:future)
21
+ assert_equal Time.local(2008, 5), next_next_may.begin
22
+ assert_equal Time.local(2008, 6), next_next_may.end
23
+
24
+ decembers = Chronic::RepeaterMonthName.new(:december)
25
+ decembers.start = @now
26
+
27
+ next_december = decembers.next(:future)
28
+ assert_equal Time.local(2006, 12), next_december.begin
29
+ assert_equal Time.local(2007, 1), next_december.end
30
+
31
+ # past
32
+
33
+ mays = Chronic::RepeaterMonthName.new(:may)
34
+ mays.start = @now
35
+
36
+ assert_equal Time.local(2006, 5), mays.next(:past).begin
37
+ assert_equal Time.local(2005, 5), mays.next(:past).begin
38
+ end
39
+
40
+ def test_this
41
+ octobers = Chronic::RepeaterMonthName.new(:october)
42
+ octobers.start = @now
43
+
44
+ this_october = octobers.this(:future)
45
+ assert_equal Time.local(2006, 10, 1), this_october.begin
46
+ assert_equal Time.local(2006, 11, 1), this_october.end
47
+
48
+ aprils = Chronic::RepeaterMonthName.new(:april)
49
+ aprils.start = @now
50
+
51
+ this_april = aprils.this(:past)
52
+ assert_equal Time.local(2006, 4, 1), this_april.begin
53
+ assert_equal Time.local(2006, 5, 1), this_april.end
54
+ end
55
+
56
+ end
@@ -0,0 +1,40 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterSeason < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
7
+ end
8
+
9
+ def test_next_future
10
+ seasons = Chronic::RepeaterSeason.new(:season)
11
+ seasons.start = @now
12
+
13
+ next_season = seasons.next(:future)
14
+ assert_equal Time.local(2006, 9, 23), next_season.begin
15
+ assert_equal Time.local(2006, 12, 21), next_season.end
16
+ end
17
+
18
+ def test_next_past
19
+ seasons = Chronic::RepeaterSeason.new(:season)
20
+ seasons.start = @now
21
+
22
+ last_season = seasons.next(:past)
23
+ assert_equal Time.local(2006, 3, 20), last_season.begin
24
+ assert_equal Time.local(2006, 6, 20), last_season.end
25
+ end
26
+
27
+ def test_this
28
+ seasons = Chronic::RepeaterSeason.new(:season)
29
+ seasons.start = @now
30
+
31
+ this_season = seasons.this(:future)
32
+ assert_equal Time.local(2006, 8, 17), this_season.begin
33
+ assert_equal Time.local(2006, 9, 22), this_season.end
34
+
35
+ this_season = seasons.this(:past)
36
+ assert_equal Time.local(2006, 6, 21), this_season.begin
37
+ assert_equal Time.local(2006, 8, 16), this_season.end
38
+ end
39
+
40
+ end