chronic 0.2.2 → 0.10.2

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.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +8 -0
  4. data/HISTORY.md +243 -0
  5. data/LICENSE +21 -0
  6. data/README.md +182 -0
  7. data/Rakefile +62 -15
  8. data/chronic.gemspec +23 -0
  9. data/lib/chronic/date.rb +82 -0
  10. data/lib/chronic/grabber.rb +24 -17
  11. data/lib/chronic/handler.rb +97 -0
  12. data/lib/chronic/handlers.rb +490 -312
  13. data/lib/chronic/mini_date.rb +38 -0
  14. data/lib/chronic/numerizer.rb +130 -0
  15. data/lib/chronic/ordinal.rb +33 -24
  16. data/lib/chronic/parser.rb +268 -0
  17. data/lib/chronic/pointer.rb +22 -17
  18. data/lib/chronic/repeater.rb +137 -107
  19. data/lib/chronic/repeaters/repeater_day.rb +51 -44
  20. data/lib/chronic/repeaters/repeater_day_name.rb +50 -43
  21. data/lib/chronic/repeaters/repeater_day_portion.rb +97 -81
  22. data/lib/chronic/repeaters/repeater_fortnight.rb +61 -54
  23. data/lib/chronic/repeaters/repeater_hour.rb +51 -44
  24. data/lib/chronic/repeaters/repeater_minute.rb +51 -44
  25. data/lib/chronic/repeaters/repeater_month.rb +79 -60
  26. data/lib/chronic/repeaters/repeater_month_name.rb +85 -83
  27. data/lib/chronic/repeaters/repeater_season.rb +110 -22
  28. data/lib/chronic/repeaters/repeater_season_name.rb +41 -22
  29. data/lib/chronic/repeaters/repeater_second.rb +41 -34
  30. data/lib/chronic/repeaters/repeater_time.rb +128 -104
  31. data/lib/chronic/repeaters/repeater_week.rb +65 -58
  32. data/lib/chronic/repeaters/repeater_weekday.rb +86 -0
  33. data/lib/chronic/repeaters/repeater_weekend.rb +59 -52
  34. data/lib/chronic/repeaters/repeater_year.rb +72 -52
  35. data/lib/chronic/scalar.rb +53 -46
  36. data/lib/chronic/season.rb +26 -0
  37. data/lib/chronic/separator.rb +174 -43
  38. data/lib/chronic/sign.rb +49 -0
  39. data/lib/chronic/span.rb +31 -0
  40. data/lib/chronic/tag.rb +37 -0
  41. data/lib/chronic/time.rb +40 -0
  42. data/lib/chronic/time_zone.rb +21 -11
  43. data/lib/chronic/token.rb +51 -0
  44. data/lib/chronic.rb +94 -69
  45. data/test/helper.rb +12 -0
  46. data/test/test_chronic.rb +183 -0
  47. data/test/test_daylight_savings.rb +118 -0
  48. data/test/{test_Handler.rb → test_handler.rb} +73 -55
  49. data/test/test_mini_date.rb +32 -0
  50. data/test/test_numerizer.rb +86 -0
  51. data/test/test_parsing.rb +891 -248
  52. data/test/{test_RepeaterDayName.rb → test_repeater_day_name.rb} +16 -17
  53. data/test/test_repeater_day_portion.rb +254 -0
  54. data/test/{test_RepeaterFortnight.rb → test_repeater_fortnight.rb} +17 -18
  55. data/test/{test_RepeaterHour.rb → test_repeater_hour.rb} +23 -20
  56. data/test/test_repeater_minute.rb +34 -0
  57. data/test/{test_RepeaterMonth.rb → test_repeater_month.rb} +21 -18
  58. data/test/{test_RepeaterMonthName.rb → test_repeater_month_name.rb} +18 -19
  59. data/test/test_repeater_season.rb +40 -0
  60. data/test/{test_RepeaterTime.rb → test_repeater_time.rb} +39 -23
  61. data/test/{test_RepeaterWeek.rb → test_repeater_week.rb} +17 -18
  62. data/test/test_repeater_weekday.rb +55 -0
  63. data/test/{test_RepeaterWeekend.rb → test_repeater_weekend.rb} +22 -23
  64. data/test/{test_RepeaterYear.rb → test_repeater_year.rb} +25 -19
  65. data/test/{test_Span.rb → test_span.rb} +7 -8
  66. data/test/{test_Token.rb → test_token.rb} +6 -7
  67. metadata +163 -85
  68. data/History.txt +0 -49
  69. data/Manifest.txt +0 -47
  70. data/README.txt +0 -149
  71. data/lib/chronic/chronic.rb +0 -239
  72. data/lib/numerizer/numerizer.rb +0 -103
  73. data/test/suite.rb +0 -9
  74. data/test/test_Chronic.rb +0 -50
  75. data/test/test_Numerizer.rb +0 -48
  76. data/test/test_Time.rb +0 -50
@@ -1,18 +1,17 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require 'helper'
2
+
3
+ class TestRepeaterDayName < TestCase
3
4
 
4
- class TestRepeaterDayName < Test::Unit::TestCase
5
-
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
@@ -0,0 +1,254 @@
1
+ require 'helper'
2
+
3
+ class TestRepeaterDayPortion < TestCase
4
+
5
+ def setup
6
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
7
+ end
8
+
9
+ def test_am_future
10
+ day_portion = Chronic::RepeaterDayPortion.new(:am)
11
+ day_portion.start = @now
12
+
13
+ next_time = day_portion.next(:future)
14
+ assert_equal Time.local(2006, 8, 17, 00), next_time.begin
15
+ assert_equal Time.local(2006, 8, 17, 11, 59, 59), next_time.end
16
+
17
+ next_next_time = day_portion.next(:future)
18
+ assert_equal Time.local(2006, 8, 18, 00), next_next_time.begin
19
+ assert_equal Time.local(2006, 8, 18, 11, 59, 59), next_next_time.end
20
+ end
21
+
22
+ def test_am_past
23
+ day_portion = Chronic::RepeaterDayPortion.new(:am)
24
+ day_portion.start = @now
25
+
26
+ next_time = day_portion.next(:past)
27
+ assert_equal Time.local(2006, 8, 16, 00), next_time.begin
28
+ assert_equal Time.local(2006, 8, 16, 11, 59, 59), next_time.end
29
+
30
+ next_next_time = day_portion.next(:past)
31
+ assert_equal Time.local(2006, 8, 15, 00), next_next_time.begin
32
+ assert_equal Time.local(2006, 8, 15, 11, 59, 59), next_next_time.end
33
+ end
34
+
35
+ def test_am_future_with_daylight_savings_time_boundary
36
+ @now = Time.local(2012,11,3,0,0,0)
37
+ day_portion = Chronic::RepeaterDayPortion.new(:am)
38
+ day_portion.start = @now
39
+
40
+ next_time = day_portion.next(:future)
41
+ assert_equal Time.local(2012, 11, 4, 00), next_time.begin
42
+ assert_equal Time.local(2012, 11, 4, 11, 59, 59), next_time.end
43
+
44
+ next_next_time = day_portion.next(:future)
45
+
46
+ assert_equal Time.local(2012, 11, 5, 00), next_next_time.begin
47
+ assert_equal Time.local(2012, 11, 5, 11, 59, 59), next_next_time.end
48
+ end
49
+
50
+ def test_pm_future
51
+ day_portion = Chronic::RepeaterDayPortion.new(:pm)
52
+ day_portion.start = @now
53
+
54
+ next_time = day_portion.next(:future)
55
+ assert_equal Time.local(2006, 8, 17, 12), next_time.begin
56
+ assert_equal Time.local(2006, 8, 17, 23, 59, 59), next_time.end
57
+
58
+ next_next_time = day_portion.next(:future)
59
+ assert_equal Time.local(2006, 8, 18, 12), next_next_time.begin
60
+ assert_equal Time.local(2006, 8, 18, 23, 59, 59), next_next_time.end
61
+ end
62
+
63
+ def test_pm_past
64
+ day_portion = Chronic::RepeaterDayPortion.new(:pm)
65
+ day_portion.start = @now
66
+
67
+ next_time = day_portion.next(:past)
68
+ assert_equal Time.local(2006, 8, 15, 12), next_time.begin
69
+ assert_equal Time.local(2006, 8, 15, 23, 59, 59), next_time.end
70
+
71
+ next_next_time = day_portion.next(:past)
72
+ assert_equal Time.local(2006, 8, 14, 12), next_next_time.begin
73
+ assert_equal Time.local(2006, 8, 14, 23, 59, 59), next_next_time.end
74
+ end
75
+
76
+ def test_pm_future_with_daylight_savings_time_boundary
77
+ @now = Time.local(2012,11,3,0,0,0)
78
+ day_portion = Chronic::RepeaterDayPortion.new(:pm)
79
+ day_portion.start = @now
80
+
81
+ next_time = day_portion.next(:future)
82
+ assert_equal Time.local(2012, 11, 3, 12), next_time.begin
83
+ assert_equal Time.local(2012, 11, 3, 23, 59, 59), next_time.end
84
+
85
+ next_next_time = day_portion.next(:future)
86
+
87
+ assert_equal Time.local(2012, 11, 4, 12), next_next_time.begin
88
+ assert_equal Time.local(2012, 11, 4, 23, 59, 59), next_next_time.end
89
+ end
90
+
91
+ def test_morning_future
92
+ day_portion = Chronic::RepeaterDayPortion.new(:morning)
93
+ day_portion.start = @now
94
+
95
+ next_time = day_portion.next(:future)
96
+ assert_equal Time.local(2006, 8, 17, 6), next_time.begin
97
+ assert_equal Time.local(2006, 8, 17, 12), next_time.end
98
+
99
+ next_next_time = day_portion.next(:future)
100
+ assert_equal Time.local(2006, 8, 18, 6), next_next_time.begin
101
+ assert_equal Time.local(2006, 8, 18, 12), next_next_time.end
102
+ end
103
+
104
+ def test_morning_past
105
+ day_portion = Chronic::RepeaterDayPortion.new(:morning)
106
+ day_portion.start = @now
107
+
108
+ next_time = day_portion.next(:past)
109
+ assert_equal Time.local(2006, 8, 16, 6), next_time.begin
110
+ assert_equal Time.local(2006, 8, 16, 12), next_time.end
111
+
112
+ next_next_time = day_portion.next(:past)
113
+ assert_equal Time.local(2006, 8, 15, 6), next_next_time.begin
114
+ assert_equal Time.local(2006, 8, 15, 12), next_next_time.end
115
+ end
116
+
117
+ def test_morning_future_with_daylight_savings_time_boundary
118
+ @now = Time.local(2012,11,3,0,0,0)
119
+ day_portion = Chronic::RepeaterDayPortion.new(:morning)
120
+ day_portion.start = @now
121
+
122
+ next_time = day_portion.next(:future)
123
+ assert_equal Time.local(2012, 11, 3, 6), next_time.begin
124
+ assert_equal Time.local(2012, 11, 3, 12), next_time.end
125
+
126
+ next_next_time = day_portion.next(:future)
127
+
128
+ assert_equal Time.local(2012, 11, 4, 6), next_next_time.begin
129
+ assert_equal Time.local(2012, 11, 4, 12), next_next_time.end
130
+ end
131
+
132
+ def test_afternoon_future
133
+ day_portion = Chronic::RepeaterDayPortion.new(:afternoon)
134
+ day_portion.start = @now
135
+
136
+ next_time = day_portion.next(:future)
137
+ assert_equal Time.local(2006, 8, 17, 13), next_time.begin
138
+ assert_equal Time.local(2006, 8, 17, 17), next_time.end
139
+
140
+ next_next_time = day_portion.next(:future)
141
+ assert_equal Time.local(2006, 8, 18, 13), next_next_time.begin
142
+ assert_equal Time.local(2006, 8, 18, 17), next_next_time.end
143
+ end
144
+
145
+ def test_afternoon_past
146
+ day_portion = Chronic::RepeaterDayPortion.new(:afternoon)
147
+ day_portion.start = @now
148
+
149
+ next_time = day_portion.next(:past)
150
+ assert_equal Time.local(2006, 8, 15, 13), next_time.begin
151
+ assert_equal Time.local(2006, 8, 15, 17), next_time.end
152
+
153
+ next_next_time = day_portion.next(:past)
154
+ assert_equal Time.local(2006, 8, 14, 13), next_next_time.begin
155
+ assert_equal Time.local(2006, 8, 14, 17), next_next_time.end
156
+ end
157
+
158
+ def test_afternoon_future_with_daylight_savings_time_boundary
159
+ @now = Time.local(2012,11,3,0,0,0)
160
+ day_portion = Chronic::RepeaterDayPortion.new(:afternoon)
161
+ day_portion.start = @now
162
+
163
+ next_time = day_portion.next(:future)
164
+ assert_equal Time.local(2012, 11, 3, 13), next_time.begin
165
+ assert_equal Time.local(2012, 11, 3, 17), next_time.end
166
+
167
+ next_next_time = day_portion.next(:future)
168
+
169
+ assert_equal Time.local(2012, 11, 4, 13), next_next_time.begin
170
+ assert_equal Time.local(2012, 11, 4, 17), next_next_time.end
171
+ end
172
+
173
+ def test_evening_future
174
+ day_portion = Chronic::RepeaterDayPortion.new(:evening)
175
+ day_portion.start = @now
176
+
177
+ next_time = day_portion.next(:future)
178
+ assert_equal Time.local(2006, 8, 16, 17), next_time.begin
179
+ assert_equal Time.local(2006, 8, 16, 20), next_time.end
180
+
181
+ next_next_time = day_portion.next(:future)
182
+ assert_equal Time.local(2006, 8, 17, 17), next_next_time.begin
183
+ assert_equal Time.local(2006, 8, 17, 20), next_next_time.end
184
+ end
185
+
186
+ def test_evening_past
187
+ day_portion = Chronic::RepeaterDayPortion.new(:evening)
188
+ day_portion.start = @now
189
+
190
+ next_time = day_portion.next(:past)
191
+ assert_equal Time.local(2006, 8, 15, 17), next_time.begin
192
+ assert_equal Time.local(2006, 8, 15, 20), next_time.end
193
+
194
+ next_next_time = day_portion.next(:past)
195
+ assert_equal Time.local(2006, 8, 14, 17), next_next_time.begin
196
+ assert_equal Time.local(2006, 8, 14, 20), next_next_time.end
197
+ end
198
+
199
+ def test_evening_future_with_daylight_savings_time_boundary
200
+ @now = Time.local(2012,11,3,0,0,0)
201
+ day_portion = Chronic::RepeaterDayPortion.new(:evening)
202
+ day_portion.start = @now
203
+
204
+ next_time = day_portion.next(:future)
205
+ assert_equal Time.local(2012, 11, 3, 17), next_time.begin
206
+ assert_equal Time.local(2012, 11, 3, 20), next_time.end
207
+
208
+ next_next_time = day_portion.next(:future)
209
+
210
+ assert_equal Time.local(2012, 11, 4, 17), next_next_time.begin
211
+ assert_equal Time.local(2012, 11, 4, 20), next_next_time.end
212
+ end
213
+
214
+ def test_night_future
215
+ day_portion = Chronic::RepeaterDayPortion.new(:night)
216
+ day_portion.start = @now
217
+
218
+ next_time = day_portion.next(:future)
219
+ assert_equal Time.local(2006, 8, 16, 20), next_time.begin
220
+ assert_equal Time.local(2006, 8, 17, 0), next_time.end
221
+
222
+ next_next_time = day_portion.next(:future)
223
+ assert_equal Time.local(2006, 8, 17, 20), next_next_time.begin
224
+ assert_equal Time.local(2006, 8, 18, 0), next_next_time.end
225
+ end
226
+
227
+ def test_night_past
228
+ day_portion = Chronic::RepeaterDayPortion.new(:night)
229
+ day_portion.start = @now
230
+
231
+ next_time = day_portion.next(:past)
232
+ assert_equal Time.local(2006, 8, 15, 20), next_time.begin
233
+ assert_equal Time.local(2006, 8, 16, 0), next_time.end
234
+
235
+ next_next_time = day_portion.next(:past)
236
+ assert_equal Time.local(2006, 8, 14, 20), next_next_time.begin
237
+ assert_equal Time.local(2006, 8, 15, 0), next_next_time.end
238
+ end
239
+
240
+ def test_night_future_with_daylight_savings_time_boundary
241
+ @now = Time.local(2012,11,3,0,0,0)
242
+ day_portion = Chronic::RepeaterDayPortion.new(:night)
243
+ day_portion.start = @now
244
+
245
+ next_time = day_portion.next(:future)
246
+ assert_equal Time.local(2012, 11, 3, 20), next_time.begin
247
+ assert_equal Time.local(2012, 11, 4, 0), next_time.end
248
+
249
+ next_next_time = day_portion.next(:future)
250
+
251
+ assert_equal Time.local(2012, 11, 4, 20), next_next_time.begin
252
+ assert_equal Time.local(2012, 11, 5, 0), next_next_time.end
253
+ end
254
+ end
@@ -1,8 +1,7 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require 'helper'
2
+
3
+ class TestRepeaterFortnight < TestCase
3
4
 
4
- class TestRepeaterFortnight < Test::Unit::TestCase
5
-
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
@@ -1,8 +1,7 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require 'helper'
2
+
3
+ class TestRepeaterHour < TestCase
3
4
 
4
- class TestRepeaterHour < Test::Unit::TestCase
5
-
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 'helper'
2
+
3
+ class TestRepeaterMinute < 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
@@ -1,47 +1,50 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require 'helper'
2
+
3
+ class TestRepeaterMonth < TestCase
3
4
 
4
- class TestRepeaterMonth < Test::Unit::TestCase
5
-
6
5
  def setup
7
6
  # Wed Aug 16 14:00:00 2006
8
7
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
9
8
  end
10
-
9
+
11
10
  def test_offset_by
12
11
  # future
13
-
12
+
14
13
  time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :future)
15
14
  assert_equal Time.local(2006, 9, 16, 14), time
16
-
15
+
17
16
  time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 5, :future)
18
17
  assert_equal Time.local(2007, 1, 16, 14), time
19
-
18
+
20
19
  # past
21
-
20
+
22
21
  time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 1, :past)
23
22
  assert_equal Time.local(2006, 7, 16, 14), time
24
-
23
+
25
24
  time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 10, :past)
26
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
27
30
  end
28
-
31
+
29
32
  def test_offset
30
33
  # future
31
-
34
+
32
35
  span = Chronic::Span.new(@now, @now + 60)
33
36
  offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :future)
34
-
37
+
35
38
  assert_equal Time.local(2006, 9, 16, 14), offset_span.begin
36
39
  assert_equal Time.local(2006, 9, 16, 14, 1), offset_span.end
37
-
40
+
38
41
  # past
39
-
42
+
40
43
  span = Chronic::Span.new(@now, @now + 60)
41
44
  offset_span = Chronic::RepeaterMonth.new(:month).offset(span, 1, :past)
42
-
45
+
43
46
  assert_equal Time.local(2006, 7, 16, 14), offset_span.begin
44
47
  assert_equal Time.local(2006, 7, 16, 14, 1), offset_span.end
45
48
  end
46
-
47
- end
49
+
50
+ end
@@ -1,57 +1,56 @@
1
- require 'chronic'
2
- require 'test/unit'
1
+ require 'helper'
2
+
3
+ class TestRepeaterMonthName < TestCase
3
4
 
4
- class TestRepeaterMonthName < Test::Unit::TestCase
5
-
6
5
  def setup
7
6
  # Wed Aug 16 14:00:00 2006
8
7
  @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
9
8
  end
10
-
9
+
11
10
  def test_next
12
11
  # future
13
-
12
+
14
13
  mays = Chronic::RepeaterMonthName.new(:may)
15
14
  mays.start = @now
16
-
15
+
17
16
  next_may = mays.next(:future)
18
17
  assert_equal Time.local(2007, 5), next_may.begin
19
18
  assert_equal Time.local(2007, 6), next_may.end
20
-
19
+
21
20
  next_next_may = mays.next(:future)
22
21
  assert_equal Time.local(2008, 5), next_next_may.begin
23
22
  assert_equal Time.local(2008, 6), next_next_may.end
24
-
23
+
25
24
  decembers = Chronic::RepeaterMonthName.new(:december)
26
25
  decembers.start = @now
27
-
26
+
28
27
  next_december = decembers.next(:future)
29
28
  assert_equal Time.local(2006, 12), next_december.begin
30
29
  assert_equal Time.local(2007, 1), next_december.end
31
-
30
+
32
31
  # past
33
-
32
+
34
33
  mays = Chronic::RepeaterMonthName.new(:may)
35
34
  mays.start = @now
36
-
35
+
37
36
  assert_equal Time.local(2006, 5), mays.next(:past).begin
38
37
  assert_equal Time.local(2005, 5), mays.next(:past).begin
39
38
  end
40
-
39
+
41
40
  def test_this
42
41
  octobers = Chronic::RepeaterMonthName.new(:october)
43
42
  octobers.start = @now
44
-
43
+
45
44
  this_october = octobers.this(:future)
46
45
  assert_equal Time.local(2006, 10, 1), this_october.begin
47
46
  assert_equal Time.local(2006, 11, 1), this_october.end
48
-
47
+
49
48
  aprils = Chronic::RepeaterMonthName.new(:april)
50
49
  aprils.start = @now
51
-
50
+
52
51
  this_april = aprils.this(:past)
53
52
  assert_equal Time.local(2006, 4, 1), this_april.begin
54
53
  assert_equal Time.local(2006, 5, 1), this_april.end
55
54
  end
56
-
57
- end
55
+
56
+ end