gitlab-chronic 0.10.3
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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.gitlab-ci.yml +14 -0
- data/.travis.yml +10 -0
- data/Gemfile +3 -0
- data/HISTORY.md +252 -0
- data/LICENSE +21 -0
- data/README.md +188 -0
- data/Rakefile +68 -0
- data/chronic.gemspec +25 -0
- data/lib/chronic.rb +155 -0
- data/lib/chronic/date.rb +81 -0
- data/lib/chronic/definition.rb +128 -0
- data/lib/chronic/dictionary.rb +36 -0
- data/lib/chronic/handler.rb +97 -0
- data/lib/chronic/handlers.rb +672 -0
- data/lib/chronic/mini_date.rb +38 -0
- data/lib/chronic/parser.rb +222 -0
- data/lib/chronic/repeaters/repeater_day.rb +54 -0
- data/lib/chronic/repeaters/repeater_day_name.rb +53 -0
- data/lib/chronic/repeaters/repeater_day_portion.rb +109 -0
- data/lib/chronic/repeaters/repeater_fortnight.rb +72 -0
- data/lib/chronic/repeaters/repeater_hour.rb +59 -0
- data/lib/chronic/repeaters/repeater_minute.rb +59 -0
- data/lib/chronic/repeaters/repeater_month.rb +80 -0
- data/lib/chronic/repeaters/repeater_month_name.rb +95 -0
- data/lib/chronic/repeaters/repeater_quarter.rb +59 -0
- data/lib/chronic/repeaters/repeater_quarter_name.rb +40 -0
- data/lib/chronic/repeaters/repeater_season.rb +111 -0
- data/lib/chronic/repeaters/repeater_season_name.rb +43 -0
- data/lib/chronic/repeaters/repeater_second.rb +43 -0
- data/lib/chronic/repeaters/repeater_time.rb +159 -0
- data/lib/chronic/repeaters/repeater_week.rb +76 -0
- data/lib/chronic/repeaters/repeater_weekday.rb +86 -0
- data/lib/chronic/repeaters/repeater_weekend.rb +67 -0
- data/lib/chronic/repeaters/repeater_year.rb +78 -0
- data/lib/chronic/season.rb +26 -0
- data/lib/chronic/span.rb +31 -0
- data/lib/chronic/tag.rb +89 -0
- data/lib/chronic/tags/grabber.rb +29 -0
- data/lib/chronic/tags/ordinal.rb +52 -0
- data/lib/chronic/tags/pointer.rb +28 -0
- data/lib/chronic/tags/repeater.rb +160 -0
- data/lib/chronic/tags/scalar.rb +89 -0
- data/lib/chronic/tags/separator.rb +123 -0
- data/lib/chronic/tags/sign.rb +35 -0
- data/lib/chronic/tags/time_zone.rb +32 -0
- data/lib/chronic/time.rb +40 -0
- data/lib/chronic/token.rb +61 -0
- data/lib/chronic/tokenizer.rb +38 -0
- data/lib/chronic/version.rb +3 -0
- data/test/helper.rb +12 -0
- data/test/test_chronic.rb +203 -0
- data/test/test_daylight_savings.rb +122 -0
- data/test/test_handler.rb +128 -0
- data/test/test_mini_date.rb +32 -0
- data/test/test_parsing.rb +1537 -0
- data/test/test_repeater_day_name.rb +51 -0
- data/test/test_repeater_day_portion.rb +254 -0
- data/test/test_repeater_fortnight.rb +62 -0
- data/test/test_repeater_hour.rb +68 -0
- data/test/test_repeater_minute.rb +34 -0
- data/test/test_repeater_month.rb +50 -0
- data/test/test_repeater_month_name.rb +56 -0
- data/test/test_repeater_quarter.rb +70 -0
- data/test/test_repeater_quarter_name.rb +198 -0
- data/test/test_repeater_season.rb +40 -0
- data/test/test_repeater_time.rb +88 -0
- data/test/test_repeater_week.rb +115 -0
- data/test/test_repeater_weekday.rb +55 -0
- data/test/test_repeater_weekend.rb +74 -0
- data/test/test_repeater_year.rb +69 -0
- data/test/test_span.rb +23 -0
- data/test/test_token.rb +31 -0
- metadata +215 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRepeaterMonth < 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 < 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,70 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRepeaterQuarter < TestCase
|
4
|
+
def setup
|
5
|
+
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_match
|
9
|
+
token = Chronic::Token.new('q')
|
10
|
+
repeater = Chronic::Repeater.scan_for_units(token)
|
11
|
+
assert_equal Chronic::RepeaterQuarter, repeater.class
|
12
|
+
assert_equal :quarter, repeater.type
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_this
|
16
|
+
quarter = Chronic::RepeaterQuarter.new(:quarter)
|
17
|
+
quarter.start = @now
|
18
|
+
|
19
|
+
time = quarter.this
|
20
|
+
assert_equal Time.local(2006, 7, 1), time.begin
|
21
|
+
assert_equal Time.local(2006, 10, 1), time.end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_next_future
|
25
|
+
quarter = Chronic::RepeaterQuarter.new(:quarter)
|
26
|
+
quarter.start = @now
|
27
|
+
|
28
|
+
time = quarter.next(:future)
|
29
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
30
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
31
|
+
|
32
|
+
time = quarter.next(:future)
|
33
|
+
assert_equal Time.local(2007, 1, 1), time.begin
|
34
|
+
assert_equal Time.local(2007, 4, 1), time.end
|
35
|
+
|
36
|
+
time = quarter.next(:future)
|
37
|
+
assert_equal Time.local(2007, 4, 1), time.begin
|
38
|
+
assert_equal Time.local(2007, 7, 1), time.end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_next_past
|
42
|
+
quarter = Chronic::RepeaterQuarter.new(:quarter)
|
43
|
+
quarter.start = @now
|
44
|
+
|
45
|
+
time = quarter.next(:past)
|
46
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
47
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
48
|
+
|
49
|
+
time = quarter.next(:past)
|
50
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
51
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
52
|
+
|
53
|
+
time = quarter.next(:past)
|
54
|
+
assert_equal Time.local(2005, 10, 1), time.begin
|
55
|
+
assert_equal Time.local(2006, 1, 1), time.end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_offset
|
59
|
+
quarter = Chronic::RepeaterQuarter.new(:quarter)
|
60
|
+
span = Chronic::Span.new(@now, @now + 1)
|
61
|
+
|
62
|
+
time = quarter.offset(span, 1, :future)
|
63
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
64
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
65
|
+
|
66
|
+
time = quarter.offset(span, 1, :past)
|
67
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
68
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRepeaterQuarterName < TestCase
|
4
|
+
def setup
|
5
|
+
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_match
|
9
|
+
%w[q1 q2 q3 q4].each do |string|
|
10
|
+
token = Chronic::Token.new(string)
|
11
|
+
repeater = Chronic::Repeater.scan_for_quarter_names(token)
|
12
|
+
assert_equal Chronic::RepeaterQuarterName, repeater.class
|
13
|
+
assert_equal string.to_sym, repeater.type
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_this_none
|
18
|
+
quarter = Chronic::RepeaterQuarterName.new(:q1)
|
19
|
+
quarter.start = @now
|
20
|
+
|
21
|
+
time = quarter.this(:none)
|
22
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
23
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
24
|
+
|
25
|
+
quarter = Chronic::RepeaterQuarterName.new(:q2)
|
26
|
+
quarter.start = @now
|
27
|
+
|
28
|
+
time = quarter.this(:none)
|
29
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
30
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
31
|
+
|
32
|
+
quarter = Chronic::RepeaterQuarterName.new(:q3)
|
33
|
+
quarter.start = @now
|
34
|
+
|
35
|
+
time = quarter.this(:none)
|
36
|
+
assert_equal Time.local(2006, 7, 1), time.begin
|
37
|
+
assert_equal Time.local(2006, 10, 1), time.end
|
38
|
+
|
39
|
+
quarter = Chronic::RepeaterQuarterName.new(:q4)
|
40
|
+
quarter.start = @now
|
41
|
+
|
42
|
+
time = quarter.this(:none)
|
43
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
44
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_this_past
|
48
|
+
quarter = Chronic::RepeaterQuarterName.new(:q1)
|
49
|
+
quarter.start = @now
|
50
|
+
|
51
|
+
time = quarter.this(:past)
|
52
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
53
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
54
|
+
|
55
|
+
quarter = Chronic::RepeaterQuarterName.new(:q2)
|
56
|
+
quarter.start = @now
|
57
|
+
|
58
|
+
time = quarter.this(:past)
|
59
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
60
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
61
|
+
|
62
|
+
quarter = Chronic::RepeaterQuarterName.new(:q3)
|
63
|
+
quarter.start = @now
|
64
|
+
|
65
|
+
time = quarter.this(:past)
|
66
|
+
assert_equal Time.local(2005, 7, 1), time.begin
|
67
|
+
assert_equal Time.local(2005, 10, 1), time.end
|
68
|
+
|
69
|
+
quarter = Chronic::RepeaterQuarterName.new(:q4)
|
70
|
+
quarter.start = @now
|
71
|
+
|
72
|
+
time = quarter.this(:past)
|
73
|
+
assert_equal Time.local(2005, 10, 1), time.begin
|
74
|
+
assert_equal Time.local(2006, 1, 1), time.end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_this_future
|
78
|
+
quarter = Chronic::RepeaterQuarterName.new(:q1)
|
79
|
+
quarter.start = @now
|
80
|
+
|
81
|
+
time = quarter.this(:future)
|
82
|
+
assert_equal Time.local(2007, 1, 1), time.begin
|
83
|
+
assert_equal Time.local(2007, 4, 1), time.end
|
84
|
+
|
85
|
+
quarter = Chronic::RepeaterQuarterName.new(:q2)
|
86
|
+
quarter.start = @now
|
87
|
+
|
88
|
+
time = quarter.this(:future)
|
89
|
+
assert_equal Time.local(2007, 4, 1), time.begin
|
90
|
+
assert_equal Time.local(2007, 7, 1), time.end
|
91
|
+
|
92
|
+
quarter = Chronic::RepeaterQuarterName.new(:q3)
|
93
|
+
quarter.start = @now
|
94
|
+
|
95
|
+
time = quarter.this(:future)
|
96
|
+
assert_equal Time.local(2007, 7, 1), time.begin
|
97
|
+
assert_equal Time.local(2007, 10, 1), time.end
|
98
|
+
|
99
|
+
quarter = Chronic::RepeaterQuarterName.new(:q4)
|
100
|
+
quarter.start = @now
|
101
|
+
|
102
|
+
time = quarter.this(:future)
|
103
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
104
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_next_future
|
108
|
+
quarter = Chronic::RepeaterQuarterName.new(:q1)
|
109
|
+
quarter.start = @now
|
110
|
+
|
111
|
+
time = quarter.next(:future)
|
112
|
+
assert_equal Time.local(2007, 1, 1), time.begin
|
113
|
+
assert_equal Time.local(2007, 4, 1), time.end
|
114
|
+
|
115
|
+
time = quarter.next(:future)
|
116
|
+
assert_equal Time.local(2008, 1, 1), time.begin
|
117
|
+
assert_equal Time.local(2008, 4, 1), time.end
|
118
|
+
|
119
|
+
quarter = Chronic::RepeaterQuarterName.new(:q2)
|
120
|
+
quarter.start = @now
|
121
|
+
|
122
|
+
time = quarter.next(:future)
|
123
|
+
assert_equal Time.local(2007, 4, 1), time.begin
|
124
|
+
assert_equal Time.local(2007, 7, 1), time.end
|
125
|
+
|
126
|
+
time = quarter.next(:future)
|
127
|
+
assert_equal Time.local(2008, 4, 1), time.begin
|
128
|
+
assert_equal Time.local(2008, 7, 1), time.end
|
129
|
+
|
130
|
+
quarter = Chronic::RepeaterQuarterName.new(:q3)
|
131
|
+
quarter.start = @now
|
132
|
+
|
133
|
+
time = quarter.next(:future)
|
134
|
+
assert_equal Time.local(2007, 7, 1), time.begin
|
135
|
+
assert_equal Time.local(2007, 10, 1), time.end
|
136
|
+
|
137
|
+
time = quarter.next(:future)
|
138
|
+
assert_equal Time.local(2008, 7, 1), time.begin
|
139
|
+
assert_equal Time.local(2008, 10, 1), time.end
|
140
|
+
|
141
|
+
quarter = Chronic::RepeaterQuarterName.new(:q4)
|
142
|
+
quarter.start = @now
|
143
|
+
|
144
|
+
time = quarter.next(:future)
|
145
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
146
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
147
|
+
|
148
|
+
time = quarter.next(:future)
|
149
|
+
assert_equal Time.local(2007, 10, 1), time.begin
|
150
|
+
assert_equal Time.local(2008, 1, 1), time.end
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_next_past
|
154
|
+
quarter = Chronic::RepeaterQuarterName.new(:q1)
|
155
|
+
quarter.start = @now
|
156
|
+
|
157
|
+
time = quarter.next(:past)
|
158
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
159
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
160
|
+
|
161
|
+
time = quarter.next(:past)
|
162
|
+
assert_equal Time.local(2005, 1, 1), time.begin
|
163
|
+
assert_equal Time.local(2005, 4, 1), time.end
|
164
|
+
|
165
|
+
quarter = Chronic::RepeaterQuarterName.new(:q2)
|
166
|
+
quarter.start = @now
|
167
|
+
|
168
|
+
time = quarter.next(:past)
|
169
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
170
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
171
|
+
|
172
|
+
time = quarter.next(:past)
|
173
|
+
assert_equal Time.local(2005, 4, 1), time.begin
|
174
|
+
assert_equal Time.local(2005, 7, 1), time.end
|
175
|
+
|
176
|
+
quarter = Chronic::RepeaterQuarterName.new(:q3)
|
177
|
+
quarter.start = @now
|
178
|
+
|
179
|
+
time = quarter.next(:past)
|
180
|
+
assert_equal Time.local(2005, 7, 1), time.begin
|
181
|
+
assert_equal Time.local(2005, 10, 1), time.end
|
182
|
+
|
183
|
+
time = quarter.next(:past)
|
184
|
+
assert_equal Time.local(2004, 7, 1), time.begin
|
185
|
+
assert_equal Time.local(2004, 10, 1), time.end
|
186
|
+
|
187
|
+
quarter = Chronic::RepeaterQuarterName.new(:q4)
|
188
|
+
quarter.start = @now
|
189
|
+
|
190
|
+
time = quarter.next(:past)
|
191
|
+
assert_equal Time.local(2005, 10, 1), time.begin
|
192
|
+
assert_equal Time.local(2006, 1, 1), time.end
|
193
|
+
|
194
|
+
time = quarter.next(:past)
|
195
|
+
assert_equal Time.local(2004, 10, 1), time.begin
|
196
|
+
assert_equal Time.local(2005, 1, 1), time.end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRepeaterSeason < 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
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRepeaterTime < 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_generic
|
11
|
+
assert_raises(ArgumentError) do
|
12
|
+
Chronic::RepeaterTime.new('00:01:02:03:004')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_next_future
|
17
|
+
t = Chronic::RepeaterTime.new('4:00')
|
18
|
+
t.start = @now
|
19
|
+
|
20
|
+
assert_equal Time.local(2006, 8, 16, 16), t.next(:future).begin
|
21
|
+
assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
|
22
|
+
|
23
|
+
t = Chronic::RepeaterTime.new('13:00')
|
24
|
+
t.start = @now
|
25
|
+
|
26
|
+
assert_equal Time.local(2006, 8, 17, 13), t.next(:future).begin
|
27
|
+
assert_equal Time.local(2006, 8, 18, 13), t.next(:future).begin
|
28
|
+
|
29
|
+
t = Chronic::RepeaterTime.new('0400')
|
30
|
+
t.start = @now
|
31
|
+
|
32
|
+
assert_equal Time.local(2006, 8, 17, 4), t.next(:future).begin
|
33
|
+
assert_equal Time.local(2006, 8, 18, 4), t.next(:future).begin
|
34
|
+
|
35
|
+
t = Chronic::RepeaterTime.new('0000')
|
36
|
+
t.start = @now
|
37
|
+
|
38
|
+
assert_equal Time.local(2006, 8, 17, 0), t.next(:future).begin
|
39
|
+
assert_equal Time.local(2006, 8, 18, 0), t.next(:future).begin
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_next_past
|
43
|
+
t = Chronic::RepeaterTime.new('4:00')
|
44
|
+
t.start = @now
|
45
|
+
|
46
|
+
assert_equal Time.local(2006, 8, 16, 4), t.next(:past).begin
|
47
|
+
assert_equal Time.local(2006, 8, 15, 16), t.next(:past).begin
|
48
|
+
|
49
|
+
t = Chronic::RepeaterTime.new('13:00')
|
50
|
+
t.start = @now
|
51
|
+
|
52
|
+
assert_equal Time.local(2006, 8, 16, 13), t.next(:past).begin
|
53
|
+
assert_equal Time.local(2006, 8, 15, 13), t.next(:past).begin
|
54
|
+
|
55
|
+
t = Chronic::RepeaterTime.new('0:00.000')
|
56
|
+
t.start = @now
|
57
|
+
|
58
|
+
assert_equal Time.local(2006, 8, 16, 0), t.next(:past).begin
|
59
|
+
assert_equal Time.local(2006, 8, 15, 0), t.next(:past).begin
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_type
|
63
|
+
t1 = Chronic::RepeaterTime.new('4')
|
64
|
+
assert_equal 14_400, t1.type.time
|
65
|
+
|
66
|
+
t1 = Chronic::RepeaterTime.new('14')
|
67
|
+
assert_equal 50_400, t1.type.time
|
68
|
+
|
69
|
+
t1 = Chronic::RepeaterTime.new('4:00')
|
70
|
+
assert_equal 14_400, t1.type.time
|
71
|
+
|
72
|
+
t1 = Chronic::RepeaterTime.new('4:30')
|
73
|
+
assert_equal 16_200, t1.type.time
|
74
|
+
|
75
|
+
t1 = Chronic::RepeaterTime.new('1400')
|
76
|
+
assert_equal 50_400, t1.type.time
|
77
|
+
|
78
|
+
t1 = Chronic::RepeaterTime.new('0400')
|
79
|
+
assert_equal 14_400, t1.type.time
|
80
|
+
|
81
|
+
t1 = Chronic::RepeaterTime.new('04')
|
82
|
+
assert_equal 14_400, t1.type.time
|
83
|
+
|
84
|
+
t1 = Chronic::RepeaterTime.new('400')
|
85
|
+
assert_equal 14_400, t1.type.time
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|