chronic 0.2.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.md +103 -0
- data/LICENSE +21 -0
- data/Manifest.txt +16 -5
- data/README.md +171 -0
- data/Rakefile +136 -15
- data/benchmark/benchmark.rb +13 -0
- data/chronic.gemspec +82 -0
- data/lib/chronic/chronic.rb +65 -147
- data/lib/chronic/grabber.rb +13 -17
- data/lib/chronic/handlers.rb +216 -138
- data/lib/chronic/mini_date.rb +27 -0
- data/lib/chronic/numerizer.rb +120 -0
- data/lib/chronic/ordinal.rb +11 -16
- data/lib/chronic/pointer.rb +11 -13
- data/lib/chronic/repeater.rb +117 -106
- data/lib/chronic/repeaters/repeater_day.rb +50 -43
- data/lib/chronic/repeaters/repeater_day_name.rb +49 -42
- data/lib/chronic/repeaters/repeater_day_portion.rb +82 -80
- data/lib/chronic/repeaters/repeater_fortnight.rb +60 -53
- data/lib/chronic/repeaters/repeater_hour.rb +50 -43
- data/lib/chronic/repeaters/repeater_minute.rb +50 -43
- data/lib/chronic/repeaters/repeater_month.rb +63 -56
- data/lib/chronic/repeaters/repeater_month_name.rb +91 -82
- data/lib/chronic/repeaters/repeater_season.rb +125 -20
- data/lib/chronic/repeaters/repeater_season_name.rb +43 -22
- data/lib/chronic/repeaters/repeater_second.rb +40 -33
- data/lib/chronic/repeaters/repeater_time.rb +118 -106
- data/lib/chronic/repeaters/repeater_week.rb +64 -57
- data/lib/chronic/repeaters/repeater_weekday.rb +86 -0
- data/lib/chronic/repeaters/repeater_weekend.rb +58 -51
- data/lib/chronic/repeaters/repeater_year.rb +58 -50
- data/lib/chronic/scalar.rb +37 -27
- data/lib/chronic/separator.rb +34 -37
- data/lib/chronic/span.rb +31 -0
- data/lib/chronic/tag.rb +26 -0
- data/lib/chronic/time_zone.rb +9 -10
- data/lib/chronic/token.rb +35 -0
- data/lib/chronic.rb +34 -25
- data/test/helper.rb +6 -0
- data/test/test_Chronic.rb +22 -18
- data/test/test_DaylightSavings.rb +118 -0
- data/test/test_Handler.rb +37 -38
- data/test/test_Numerizer.rb +66 -42
- data/test/test_RepeaterDayName.rb +15 -16
- data/test/test_RepeaterFortnight.rb +16 -17
- data/test/test_RepeaterHour.rb +22 -19
- data/test/test_RepeaterMinute.rb +34 -0
- data/test/test_RepeaterMonth.rb +16 -17
- data/test/test_RepeaterMonthName.rb +17 -18
- data/test/test_RepeaterTime.rb +20 -22
- data/test/test_RepeaterWeek.rb +16 -17
- data/test/test_RepeaterWeekday.rb +55 -0
- data/test/test_RepeaterWeekend.rb +21 -22
- data/test/test_RepeaterYear.rb +17 -18
- data/test/test_Span.rb +5 -6
- data/test/test_Time.rb +11 -12
- data/test/test_Token.rb +5 -6
- data/test/test_parsing.rb +395 -208
- metadata +68 -52
- data/History.txt +0 -53
- data/README.txt +0 -149
- data/lib/numerizer/numerizer.rb +0 -103
- data/test/suite.rb +0 -9
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[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
|
data/test/test_Handler.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'test/unit'
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[helper])
|
|
3
2
|
|
|
4
3
|
class TestHandler < Test::Unit::TestCase
|
|
5
|
-
|
|
4
|
+
|
|
6
5
|
def setup
|
|
7
6
|
# Wed Aug 16 14:00:00 UTC 2006
|
|
8
7
|
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
|
@@ -10,101 +9,101 @@ class TestHandler < Test::Unit::TestCase
|
|
|
10
9
|
|
|
11
10
|
def test_handler_class_1
|
|
12
11
|
handler = Chronic::Handler.new([:repeater], :handler)
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
tokens = [Chronic::Token.new('friday')]
|
|
15
14
|
tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
|
|
16
|
-
|
|
15
|
+
|
|
17
16
|
assert handler.match(tokens, Chronic.definitions)
|
|
18
|
-
|
|
17
|
+
|
|
19
18
|
tokens << Chronic::Token.new('afternoon')
|
|
20
19
|
tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))
|
|
21
|
-
|
|
20
|
+
|
|
22
21
|
assert !handler.match(tokens, Chronic.definitions)
|
|
23
22
|
end
|
|
24
|
-
|
|
23
|
+
|
|
25
24
|
def test_handler_class_2
|
|
26
25
|
handler = Chronic::Handler.new([:repeater, :repeater?], :handler)
|
|
27
|
-
|
|
26
|
+
|
|
28
27
|
tokens = [Chronic::Token.new('friday')]
|
|
29
28
|
tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
|
|
30
|
-
|
|
29
|
+
|
|
31
30
|
assert handler.match(tokens, Chronic.definitions)
|
|
32
|
-
|
|
31
|
+
|
|
33
32
|
tokens << Chronic::Token.new('afternoon')
|
|
34
33
|
tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))
|
|
35
|
-
|
|
34
|
+
|
|
36
35
|
assert handler.match(tokens, Chronic.definitions)
|
|
37
|
-
|
|
36
|
+
|
|
38
37
|
tokens << Chronic::Token.new('afternoon')
|
|
39
38
|
tokens[2].tag(Chronic::RepeaterDayPortion.new(:afternoon))
|
|
40
|
-
|
|
39
|
+
|
|
41
40
|
assert !handler.match(tokens, Chronic.definitions)
|
|
42
41
|
end
|
|
43
|
-
|
|
42
|
+
|
|
44
43
|
def test_handler_class_3
|
|
45
44
|
handler = Chronic::Handler.new([:repeater, 'time?'], :handler)
|
|
46
|
-
|
|
45
|
+
|
|
47
46
|
tokens = [Chronic::Token.new('friday')]
|
|
48
47
|
tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
|
|
49
|
-
|
|
48
|
+
|
|
50
49
|
assert handler.match(tokens, Chronic.definitions)
|
|
51
|
-
|
|
50
|
+
|
|
52
51
|
tokens << Chronic::Token.new('afternoon')
|
|
53
52
|
tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))
|
|
54
|
-
|
|
53
|
+
|
|
55
54
|
assert !handler.match(tokens, Chronic.definitions)
|
|
56
55
|
end
|
|
57
|
-
|
|
56
|
+
|
|
58
57
|
def test_handler_class_4
|
|
59
58
|
handler = Chronic::Handler.new([:repeater_month_name, :scalar_day, 'time?'], :handler)
|
|
60
|
-
|
|
59
|
+
|
|
61
60
|
tokens = [Chronic::Token.new('may')]
|
|
62
61
|
tokens[0].tag(Chronic::RepeaterMonthName.new(:may))
|
|
63
|
-
|
|
62
|
+
|
|
64
63
|
assert !handler.match(tokens, Chronic.definitions)
|
|
65
|
-
|
|
64
|
+
|
|
66
65
|
tokens << Chronic::Token.new('27')
|
|
67
66
|
tokens[1].tag(Chronic::ScalarDay.new(27))
|
|
68
|
-
|
|
67
|
+
|
|
69
68
|
assert handler.match(tokens, Chronic.definitions)
|
|
70
69
|
end
|
|
71
|
-
|
|
70
|
+
|
|
72
71
|
def test_handler_class_5
|
|
73
72
|
handler = Chronic::Handler.new([:repeater, 'time?'], :handler)
|
|
74
|
-
|
|
73
|
+
|
|
75
74
|
tokens = [Chronic::Token.new('friday')]
|
|
76
75
|
tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
|
|
77
|
-
|
|
76
|
+
|
|
78
77
|
assert handler.match(tokens, Chronic.definitions)
|
|
79
|
-
|
|
78
|
+
|
|
80
79
|
tokens << Chronic::Token.new('5:00')
|
|
81
80
|
tokens[1].tag(Chronic::RepeaterTime.new('5:00'))
|
|
82
|
-
|
|
81
|
+
|
|
83
82
|
assert handler.match(tokens, Chronic.definitions)
|
|
84
|
-
|
|
83
|
+
|
|
85
84
|
tokens << Chronic::Token.new('pm')
|
|
86
85
|
tokens[2].tag(Chronic::RepeaterDayPortion.new(:pm))
|
|
87
|
-
|
|
86
|
+
|
|
88
87
|
assert handler.match(tokens, Chronic.definitions)
|
|
89
88
|
end
|
|
90
|
-
|
|
89
|
+
|
|
91
90
|
def test_handler_class_6
|
|
92
91
|
handler = Chronic::Handler.new([:scalar, :repeater, :pointer], :handler)
|
|
93
|
-
|
|
92
|
+
|
|
94
93
|
tokens = [Chronic::Token.new('3'),
|
|
95
94
|
Chronic::Token.new('years'),
|
|
96
95
|
Chronic::Token.new('past')]
|
|
97
|
-
|
|
96
|
+
|
|
98
97
|
tokens[0].tag(Chronic::Scalar.new(3))
|
|
99
98
|
tokens[1].tag(Chronic::RepeaterYear.new(:year))
|
|
100
99
|
tokens[2].tag(Chronic::Pointer.new(:past))
|
|
101
|
-
|
|
100
|
+
|
|
102
101
|
assert handler.match(tokens, Chronic.definitions)
|
|
103
102
|
end
|
|
104
|
-
|
|
103
|
+
|
|
105
104
|
def test_constantize
|
|
106
105
|
handler = Chronic::Handler.new([], :handler)
|
|
107
106
|
assert_equal Chronic::RepeaterTime, handler.constantize(:repeater_time)
|
|
108
107
|
end
|
|
109
|
-
|
|
110
|
-
end
|
|
108
|
+
|
|
109
|
+
end
|
data/test/test_Numerizer.rb
CHANGED
|
@@ -1,48 +1,72 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'chronic'
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[helper])
|
|
3
2
|
|
|
4
3
|
class ParseNumbersTest < Test::Unit::TestCase
|
|
5
4
|
|
|
6
5
|
def test_straight_parsing
|
|
7
|
-
strings = {
|
|
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
|
-
|
|
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)
|
|
46
66
|
end
|
|
47
67
|
end
|
|
48
|
-
|
|
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
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'test/unit'
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[helper])
|
|
3
2
|
|
|
4
3
|
class TestRepeaterDayName < Test::Unit::TestCase
|
|
5
|
-
|
|
4
|
+
|
|
6
5
|
def setup
|
|
7
6
|
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
|
8
7
|
end
|
|
9
|
-
|
|
8
|
+
|
|
10
9
|
def test_match
|
|
11
10
|
token = Chronic::Token.new('saturday')
|
|
12
11
|
repeater = Chronic::Repeater.scan_for_day_names(token)
|
|
13
12
|
assert_equal Chronic::RepeaterDayName, repeater.class
|
|
14
13
|
assert_equal :saturday, repeater.type
|
|
15
|
-
|
|
14
|
+
|
|
16
15
|
token = Chronic::Token.new('sunday')
|
|
17
16
|
repeater = Chronic::Repeater.scan_for_day_names(token)
|
|
18
17
|
assert_equal Chronic::RepeaterDayName, repeater.class
|
|
@@ -22,31 +21,31 @@ class TestRepeaterDayName < Test::Unit::TestCase
|
|
|
22
21
|
def test_next_future
|
|
23
22
|
mondays = Chronic::RepeaterDayName.new(:monday)
|
|
24
23
|
mondays.start = @now
|
|
25
|
-
|
|
24
|
+
|
|
26
25
|
span = mondays.next(:future)
|
|
27
|
-
|
|
26
|
+
|
|
28
27
|
assert_equal Time.local(2006, 8, 21), span.begin
|
|
29
|
-
assert_equal Time.local(2006, 8, 22), span.end
|
|
28
|
+
assert_equal Time.local(2006, 8, 22), span.end
|
|
30
29
|
|
|
31
30
|
span = mondays.next(:future)
|
|
32
|
-
|
|
31
|
+
|
|
33
32
|
assert_equal Time.local(2006, 8, 28), span.begin
|
|
34
33
|
assert_equal Time.local(2006, 8, 29), span.end
|
|
35
34
|
end
|
|
36
|
-
|
|
35
|
+
|
|
37
36
|
def test_next_past
|
|
38
37
|
mondays = Chronic::RepeaterDayName.new(:monday)
|
|
39
38
|
mondays.start = @now
|
|
40
|
-
|
|
39
|
+
|
|
41
40
|
span = mondays.next(:past)
|
|
42
|
-
|
|
41
|
+
|
|
43
42
|
assert_equal Time.local(2006, 8, 14), span.begin
|
|
44
|
-
assert_equal Time.local(2006, 8, 15), span.end
|
|
43
|
+
assert_equal Time.local(2006, 8, 15), span.end
|
|
45
44
|
|
|
46
45
|
span = mondays.next(:past)
|
|
47
|
-
|
|
46
|
+
|
|
48
47
|
assert_equal Time.local(2006, 8, 7), span.begin
|
|
49
48
|
assert_equal Time.local(2006, 8, 8), span.end
|
|
50
49
|
end
|
|
51
|
-
|
|
52
|
-
end
|
|
50
|
+
|
|
51
|
+
end
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'test/unit'
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[helper])
|
|
3
2
|
|
|
4
3
|
class TestRepeaterFortnight < Test::Unit::TestCase
|
|
5
|
-
|
|
4
|
+
|
|
6
5
|
def setup
|
|
7
6
|
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
|
8
7
|
end
|
|
@@ -10,54 +9,54 @@ class TestRepeaterFortnight < Test::Unit::TestCase
|
|
|
10
9
|
def test_next_future
|
|
11
10
|
fortnights = Chronic::RepeaterFortnight.new(:fortnight)
|
|
12
11
|
fortnights.start = @now
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
next_fortnight = fortnights.next(:future)
|
|
15
14
|
assert_equal Time.local(2006, 8, 20), next_fortnight.begin
|
|
16
15
|
assert_equal Time.local(2006, 9, 3), next_fortnight.end
|
|
17
|
-
|
|
16
|
+
|
|
18
17
|
next_next_fortnight = fortnights.next(:future)
|
|
19
18
|
assert_equal Time.local(2006, 9, 3), next_next_fortnight.begin
|
|
20
19
|
assert_equal Time.local(2006, 9, 17), next_next_fortnight.end
|
|
21
20
|
end
|
|
22
|
-
|
|
21
|
+
|
|
23
22
|
def test_next_past
|
|
24
23
|
fortnights = Chronic::RepeaterFortnight.new(:fortnight)
|
|
25
24
|
fortnights.start = @now
|
|
26
|
-
|
|
25
|
+
|
|
27
26
|
last_fortnight = fortnights.next(:past)
|
|
28
27
|
assert_equal Time.local(2006, 7, 30), last_fortnight.begin
|
|
29
28
|
assert_equal Time.local(2006, 8, 13), last_fortnight.end
|
|
30
|
-
|
|
29
|
+
|
|
31
30
|
last_last_fortnight = fortnights.next(:past)
|
|
32
31
|
assert_equal Time.local(2006, 7, 16), last_last_fortnight.begin
|
|
33
32
|
assert_equal Time.local(2006, 7, 30), last_last_fortnight.end
|
|
34
33
|
end
|
|
35
|
-
|
|
34
|
+
|
|
36
35
|
def test_this_future
|
|
37
36
|
fortnights = Chronic::RepeaterFortnight.new(:fortnight)
|
|
38
37
|
fortnights.start = @now
|
|
39
|
-
|
|
38
|
+
|
|
40
39
|
this_fortnight = fortnights.this(:future)
|
|
41
40
|
assert_equal Time.local(2006, 8, 16, 15), this_fortnight.begin
|
|
42
41
|
assert_equal Time.local(2006, 8, 27), this_fortnight.end
|
|
43
42
|
end
|
|
44
|
-
|
|
43
|
+
|
|
45
44
|
def test_this_past
|
|
46
45
|
fortnights = Chronic::RepeaterFortnight.new(:fortnight)
|
|
47
46
|
fortnights.start = @now
|
|
48
|
-
|
|
47
|
+
|
|
49
48
|
this_fortnight = fortnights.this(:past)
|
|
50
49
|
assert_equal Time.local(2006, 8, 13, 0), this_fortnight.begin
|
|
51
50
|
assert_equal Time.local(2006, 8, 16, 14), this_fortnight.end
|
|
52
51
|
end
|
|
53
|
-
|
|
52
|
+
|
|
54
53
|
def test_offset
|
|
55
54
|
span = Chronic::Span.new(@now, @now + 1)
|
|
56
|
-
|
|
55
|
+
|
|
57
56
|
offset_span = Chronic::RepeaterWeek.new(:week).offset(span, 3, :future)
|
|
58
|
-
|
|
57
|
+
|
|
59
58
|
assert_equal Time.local(2006, 9, 6, 14), offset_span.begin
|
|
60
59
|
assert_equal Time.local(2006, 9, 6, 14, 0, 1), offset_span.end
|
|
61
60
|
end
|
|
62
|
-
|
|
63
|
-
end
|
|
61
|
+
|
|
62
|
+
end
|
data/test/test_RepeaterHour.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'test/unit'
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[helper])
|
|
3
2
|
|
|
4
3
|
class TestRepeaterHour < Test::Unit::TestCase
|
|
5
|
-
|
|
4
|
+
|
|
6
5
|
def setup
|
|
7
6
|
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
|
8
7
|
end
|
|
@@ -10,56 +9,60 @@ class TestRepeaterHour < Test::Unit::TestCase
|
|
|
10
9
|
def test_next_future
|
|
11
10
|
hours = Chronic::RepeaterHour.new(:hour)
|
|
12
11
|
hours.start = @now
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
next_hour = hours.next(:future)
|
|
15
14
|
assert_equal Time.local(2006, 8, 16, 15), next_hour.begin
|
|
16
15
|
assert_equal Time.local(2006, 8, 16, 16), next_hour.end
|
|
17
|
-
|
|
16
|
+
|
|
18
17
|
next_next_hour = hours.next(:future)
|
|
19
18
|
assert_equal Time.local(2006, 8, 16, 16), next_next_hour.begin
|
|
20
19
|
assert_equal Time.local(2006, 8, 16, 17), next_next_hour.end
|
|
21
20
|
end
|
|
22
|
-
|
|
21
|
+
|
|
23
22
|
def test_next_past
|
|
24
23
|
hours = Chronic::RepeaterHour.new(:hour)
|
|
25
24
|
hours.start = @now
|
|
26
|
-
|
|
25
|
+
|
|
27
26
|
past_hour = hours.next(:past)
|
|
28
27
|
assert_equal Time.local(2006, 8, 16, 13), past_hour.begin
|
|
29
28
|
assert_equal Time.local(2006, 8, 16, 14), past_hour.end
|
|
30
|
-
|
|
29
|
+
|
|
31
30
|
past_past_hour = hours.next(:past)
|
|
32
31
|
assert_equal Time.local(2006, 8, 16, 12), past_past_hour.begin
|
|
33
32
|
assert_equal Time.local(2006, 8, 16, 13), past_past_hour.end
|
|
34
33
|
end
|
|
35
|
-
|
|
34
|
+
|
|
36
35
|
def test_this
|
|
37
36
|
@now = Time.local(2006, 8, 16, 14, 30)
|
|
38
|
-
|
|
37
|
+
|
|
39
38
|
hours = Chronic::RepeaterHour.new(:hour)
|
|
40
39
|
hours.start = @now
|
|
41
|
-
|
|
40
|
+
|
|
42
41
|
this_hour = hours.this(:future)
|
|
43
42
|
assert_equal Time.local(2006, 8, 16, 14, 31), this_hour.begin
|
|
44
43
|
assert_equal Time.local(2006, 8, 16, 15), this_hour.end
|
|
45
|
-
|
|
44
|
+
|
|
46
45
|
this_hour = hours.this(:past)
|
|
47
46
|
assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
|
|
48
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
|
|
49
52
|
end
|
|
50
|
-
|
|
53
|
+
|
|
51
54
|
def test_offset
|
|
52
55
|
span = Chronic::Span.new(@now, @now + 1)
|
|
53
|
-
|
|
56
|
+
|
|
54
57
|
offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 3, :future)
|
|
55
|
-
|
|
58
|
+
|
|
56
59
|
assert_equal Time.local(2006, 8, 16, 17), offset_span.begin
|
|
57
60
|
assert_equal Time.local(2006, 8, 16, 17, 0, 1), offset_span.end
|
|
58
|
-
|
|
61
|
+
|
|
59
62
|
offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 24, :past)
|
|
60
|
-
|
|
63
|
+
|
|
61
64
|
assert_equal Time.local(2006, 8, 15, 14), offset_span.begin
|
|
62
65
|
assert_equal Time.local(2006, 8, 15, 14, 0, 1), offset_span.end
|
|
63
66
|
end
|
|
64
|
-
|
|
65
|
-
end
|
|
67
|
+
|
|
68
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[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
|