chronic-mmlac 0.6.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/.gitignore +5 -0
- data/.yardopts +3 -0
- data/HISTORY.md +174 -0
- data/LICENSE +21 -0
- data/README.md +177 -0
- data/Rakefile +46 -0
- data/chronic.gemspec +17 -0
- data/lib/chronic/chronic.rb +325 -0
- data/lib/chronic/grabber.rb +31 -0
- data/lib/chronic/handler.rb +90 -0
- data/lib/chronic/handlers.rb +465 -0
- data/lib/chronic/mini_date.rb +38 -0
- data/lib/chronic/numerizer.rb +121 -0
- data/lib/chronic/ordinal.rb +44 -0
- data/lib/chronic/pointer.rb +30 -0
- data/lib/chronic/repeater.rb +135 -0
- data/lib/chronic/repeaters/repeater_day.rb +53 -0
- data/lib/chronic/repeaters/repeater_day_name.rb +52 -0
- data/lib/chronic/repeaters/repeater_day_portion.rb +94 -0
- data/lib/chronic/repeaters/repeater_fortnight.rb +71 -0
- data/lib/chronic/repeaters/repeater_hour.rb +58 -0
- data/lib/chronic/repeaters/repeater_minute.rb +58 -0
- data/lib/chronic/repeaters/repeater_month.rb +79 -0
- data/lib/chronic/repeaters/repeater_month_name.rb +94 -0
- data/lib/chronic/repeaters/repeater_season.rb +109 -0
- data/lib/chronic/repeaters/repeater_season_name.rb +43 -0
- data/lib/chronic/repeaters/repeater_second.rb +42 -0
- data/lib/chronic/repeaters/repeater_time.rb +128 -0
- data/lib/chronic/repeaters/repeater_week.rb +74 -0
- data/lib/chronic/repeaters/repeater_weekday.rb +85 -0
- data/lib/chronic/repeaters/repeater_weekend.rb +66 -0
- data/lib/chronic/repeaters/repeater_year.rb +77 -0
- data/lib/chronic/scalar.rb +109 -0
- data/lib/chronic/season.rb +37 -0
- data/lib/chronic/separator.rb +88 -0
- data/lib/chronic/span.rb +31 -0
- data/lib/chronic/tag.rb +42 -0
- data/lib/chronic/time_zone.rb +30 -0
- data/lib/chronic/token.rb +45 -0
- data/lib/chronic.rb +118 -0
- data/test/helper.rb +6 -0
- data/test/test_Chronic.rb +148 -0
- data/test/test_DaylightSavings.rb +118 -0
- data/test/test_Handler.rb +104 -0
- data/test/test_MiniDate.rb +32 -0
- data/test/test_Numerizer.rb +72 -0
- data/test/test_RepeaterDayName.rb +51 -0
- data/test/test_RepeaterFortnight.rb +62 -0
- data/test/test_RepeaterHour.rb +68 -0
- data/test/test_RepeaterMinute.rb +34 -0
- data/test/test_RepeaterMonth.rb +50 -0
- data/test/test_RepeaterMonthName.rb +56 -0
- data/test/test_RepeaterSeason.rb +40 -0
- data/test/test_RepeaterTime.rb +70 -0
- data/test/test_RepeaterWeek.rb +62 -0
- data/test/test_RepeaterWeekday.rb +55 -0
- data/test/test_RepeaterWeekend.rb +74 -0
- data/test/test_RepeaterYear.rb +69 -0
- data/test/test_Span.rb +23 -0
- data/test/test_Token.rb +25 -0
- data/test/test_parsing.rb +886 -0
- metadata +132 -0
@@ -0,0 +1,886 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestParsing < Test::Unit::TestCase
|
4
|
+
# Wed Aug 16 14:00:00 UTC 2006
|
5
|
+
TIME_2006_08_16_14_00_00 = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@time_2006_08_16_14_00_00 = TIME_2006_08_16_14_00_00
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_handle_rmn_sd
|
12
|
+
time = parse_now("aug 3")
|
13
|
+
assert_equal Time.local(2006, 8, 3, 12), time
|
14
|
+
|
15
|
+
time = parse_now("aug 3", :context => :past)
|
16
|
+
assert_equal Time.local(2006, 8, 3, 12), time
|
17
|
+
|
18
|
+
time = parse_now("aug 20")
|
19
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
20
|
+
|
21
|
+
time = parse_now("aug 20", :context => :future)
|
22
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
23
|
+
|
24
|
+
time = parse_now("may 27")
|
25
|
+
assert_equal Time.local(2007, 5, 27, 12), time
|
26
|
+
|
27
|
+
time = parse_now("may 28", :context => :past)
|
28
|
+
assert_equal Time.local(2006, 5, 28, 12), time
|
29
|
+
|
30
|
+
time = parse_now("may 28 5pm", :context => :past)
|
31
|
+
assert_equal Time.local(2006, 5, 28, 17), time
|
32
|
+
|
33
|
+
time = parse_now("may 28 at 5pm", :context => :past)
|
34
|
+
assert_equal Time.local(2006, 5, 28, 17), time
|
35
|
+
|
36
|
+
time = parse_now("may 28 at 5:32.19pm", :context => :past)
|
37
|
+
assert_equal Time.local(2006, 5, 28, 17, 32, 19), time
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_handle_rmn_sd_on
|
41
|
+
time = parse_now("5pm on may 28")
|
42
|
+
assert_equal Time.local(2007, 5, 28, 17), time
|
43
|
+
|
44
|
+
time = parse_now("5pm may 28")
|
45
|
+
assert_equal Time.local(2007, 5, 28, 17), time
|
46
|
+
|
47
|
+
time = parse_now("5 on may 28", :ambiguous_time_range => :none)
|
48
|
+
assert_equal Time.local(2007, 5, 28, 05), time
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_handle_rmn_od
|
52
|
+
time = parse_now("may 27th")
|
53
|
+
assert_equal Time.local(2007, 5, 27, 12), time
|
54
|
+
|
55
|
+
time = parse_now("may 27th", :context => :past)
|
56
|
+
assert_equal Time.local(2006, 5, 27, 12), time
|
57
|
+
|
58
|
+
time = parse_now("may 27th 5:00 pm", :context => :past)
|
59
|
+
assert_equal Time.local(2006, 5, 27, 17), time
|
60
|
+
|
61
|
+
time = parse_now("may 27th at 5pm", :context => :past)
|
62
|
+
assert_equal Time.local(2006, 5, 27, 17), time
|
63
|
+
|
64
|
+
time = parse_now("may 27th at 5", :ambiguous_time_range => :none)
|
65
|
+
assert_equal Time.local(2007, 5, 27, 5), time
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_handle_od_rmn
|
69
|
+
time = parse_now("22nd February")
|
70
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
71
|
+
|
72
|
+
time = parse_now("31st of may at 6:30pm")
|
73
|
+
assert_equal Time.local(2007, 5, 31, 18, 30), time
|
74
|
+
|
75
|
+
time = parse_now("11th december 8am")
|
76
|
+
assert_equal Time.local(2006, 12, 11, 8), time
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_handle_sy_rmn_od
|
80
|
+
time = parse_now("2009 May 22nd")
|
81
|
+
assert_equal Time.local(2009, 05, 22, 12), time
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_handle_sd_rmn
|
85
|
+
time = parse_now("22 February")
|
86
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
87
|
+
|
88
|
+
time = parse_now("31 of may at 6:30pm")
|
89
|
+
assert_equal Time.local(2007, 5, 31, 18, 30), time
|
90
|
+
|
91
|
+
time = parse_now("11 december 8am")
|
92
|
+
assert_equal Time.local(2006, 12, 11, 8), time
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_handle_rmn_od_on
|
96
|
+
time = parse_now("5:00 pm may 27th", :context => :past)
|
97
|
+
assert_equal Time.local(2006, 5, 27, 17), time
|
98
|
+
|
99
|
+
time = parse_now("05:00 pm may 27th", :context => :past)
|
100
|
+
assert_equal Time.local(2006, 5, 27, 17), time
|
101
|
+
|
102
|
+
time = parse_now("5pm on may 27th", :context => :past)
|
103
|
+
assert_equal Time.local(2006, 5, 27, 17), time
|
104
|
+
|
105
|
+
time = parse_now("5 on may 27th", :ambiguous_time_range => :none)
|
106
|
+
assert_equal Time.local(2007, 5, 27, 5), time
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_handle_rmn_sy
|
110
|
+
time = parse_now("may 97")
|
111
|
+
assert_equal Time.local(1997, 5, 16, 12), time
|
112
|
+
|
113
|
+
time = parse_now("may 33", :ambiguous_year_future_bias => 10)
|
114
|
+
assert_equal Time.local(2033, 5, 16, 12), time
|
115
|
+
|
116
|
+
time = parse_now("may 32")
|
117
|
+
assert_equal Time.local(2032, 5, 16, 12, 0, 0), time
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_handle_rdn_rmn_sd_t_tz_sy
|
121
|
+
time = parse_now("Mon Apr 02 17:00:00 PDT 2007")
|
122
|
+
assert_equal 1175558400, time.to_i
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_handle_sy_sm_sd_t_tz
|
126
|
+
time = parse_now("2011-07-03 22:11:35 +0100")
|
127
|
+
assert_equal 1309727495, time.to_i
|
128
|
+
|
129
|
+
time = parse_now("2011-07-03 22:11:35 +01:00")
|
130
|
+
assert_equal 1309727495, time.to_i
|
131
|
+
|
132
|
+
time = parse_now("2011-07-03 21:11:35 UTC")
|
133
|
+
assert_equal 1309727495, time.to_i
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_handle_rmn_sd_sy
|
137
|
+
time = parse_now("November 18, 2010")
|
138
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
139
|
+
|
140
|
+
time = parse_now("Jan 1,2010")
|
141
|
+
assert_equal Time.local(2010, 1, 1, 12), time
|
142
|
+
|
143
|
+
time = parse_now("February 14, 2004")
|
144
|
+
assert_equal Time.local(2004, 2, 14, 12), time
|
145
|
+
|
146
|
+
time = parse_now("jan 3 2010")
|
147
|
+
assert_equal Time.local(2010, 1, 3, 12), time
|
148
|
+
|
149
|
+
time = parse_now("jan 3 2010 midnight")
|
150
|
+
assert_equal Time.local(2010, 1, 4, 0), time
|
151
|
+
|
152
|
+
time = parse_now("jan 3 2010 at midnight")
|
153
|
+
assert_equal Time.local(2010, 1, 4, 0), time
|
154
|
+
|
155
|
+
time = parse_now("jan 3 2010 at 4", :ambiguous_time_range => :none)
|
156
|
+
assert_equal Time.local(2010, 1, 3, 4), time
|
157
|
+
|
158
|
+
time = parse_now("may 27, 1979")
|
159
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
160
|
+
|
161
|
+
time = parse_now("may 27 79")
|
162
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
163
|
+
|
164
|
+
time = parse_now("may 27 79 4:30")
|
165
|
+
assert_equal Time.local(1979, 5, 27, 16, 30), time
|
166
|
+
|
167
|
+
time = parse_now("may 27 79 at 4:30", :ambiguous_time_range => :none)
|
168
|
+
assert_equal Time.local(1979, 5, 27, 4, 30), time
|
169
|
+
|
170
|
+
time = parse_now("may 27 32")
|
171
|
+
assert_equal Time.local(2032, 5, 27, 12, 0, 0), time
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_handle_rmn_od_sy
|
175
|
+
time = parse_now("may 1st 01")
|
176
|
+
assert_equal Time.local(2001, 5, 1, 12), time
|
177
|
+
|
178
|
+
time = parse_now("November 18th 2010")
|
179
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
180
|
+
|
181
|
+
time = parse_now("November 18th, 2010")
|
182
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
183
|
+
|
184
|
+
time = parse_now("November 18th 2010 midnight")
|
185
|
+
assert_equal Time.local(2010, 11, 19, 0), time
|
186
|
+
|
187
|
+
time = parse_now("November 18th 2010 at midnight")
|
188
|
+
assert_equal Time.local(2010, 11, 19, 0), time
|
189
|
+
|
190
|
+
time = parse_now("November 18th 2010 at 4")
|
191
|
+
assert_equal Time.local(2010, 11, 18, 16), time
|
192
|
+
|
193
|
+
time = parse_now("November 18th 2010 at 4", :ambiguous_time_range => :none)
|
194
|
+
assert_equal Time.local(2010, 11, 18, 4), time
|
195
|
+
|
196
|
+
time = parse_now("March 30th, 1979")
|
197
|
+
assert_equal Time.local(1979, 3, 30, 12), time
|
198
|
+
|
199
|
+
time = parse_now("March 30th 79")
|
200
|
+
assert_equal Time.local(1979, 3, 30, 12), time
|
201
|
+
|
202
|
+
time = parse_now("March 30th 79 4:30")
|
203
|
+
assert_equal Time.local(1979, 3, 30, 16, 30), time
|
204
|
+
|
205
|
+
time = parse_now("March 30th 79 at 4:30", :ambiguous_time_range => :none)
|
206
|
+
assert_equal Time.local(1979, 3, 30, 4, 30), time
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_handle_od_rmn_sy
|
210
|
+
time = parse_now("22nd February 2012")
|
211
|
+
assert_equal Time.local(2012, 2, 22, 12), time
|
212
|
+
|
213
|
+
time = parse_now("11th december 79")
|
214
|
+
assert_equal Time.local(1979, 12, 11, 12), time
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_handle_sd_rmn_sy
|
218
|
+
time = parse_now("3 jan 2010")
|
219
|
+
assert_equal Time.local(2010, 1, 3, 12), time
|
220
|
+
|
221
|
+
time = parse_now("3 jan 2010 4pm")
|
222
|
+
assert_equal Time.local(2010, 1, 3, 16), time
|
223
|
+
|
224
|
+
time = parse_now("27 Oct 2006 7:30pm")
|
225
|
+
assert_equal Time.local(2006, 10, 27, 19, 30), time
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_handle_sm_sd_sy
|
229
|
+
time = parse_now("5/27/1979")
|
230
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
231
|
+
|
232
|
+
time = parse_now("5/27/1979 4am")
|
233
|
+
assert_equal Time.local(1979, 5, 27, 4), time
|
234
|
+
|
235
|
+
time = parse_now("7/12/11")
|
236
|
+
assert_equal Time.local(2011, 7, 12, 12), time
|
237
|
+
|
238
|
+
time = parse_now("7/12/11", :endian_precedence => :little)
|
239
|
+
assert_equal Time.local(2011, 12, 7, 12), time
|
240
|
+
|
241
|
+
# month day overflows
|
242
|
+
time = parse_now("30/2/2000")
|
243
|
+
assert_nil time
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_handle_sd_sm_sy
|
247
|
+
time = parse_now("27/5/1979")
|
248
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
249
|
+
|
250
|
+
time = parse_now("27/5/1979 @ 0700")
|
251
|
+
assert_equal Time.local(1979, 5, 27, 7), time
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_handle_sy_sm_sd
|
255
|
+
time = parse_now("2000-1-1")
|
256
|
+
assert_equal Time.local(2000, 1, 1, 12), time
|
257
|
+
|
258
|
+
time = parse_now("2006-08-20")
|
259
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
260
|
+
|
261
|
+
time = parse_now("2006-08-20 7pm")
|
262
|
+
assert_equal Time.local(2006, 8, 20, 19), time
|
263
|
+
|
264
|
+
time = parse_now("2006-08-20 03:00")
|
265
|
+
assert_equal Time.local(2006, 8, 20, 3), time
|
266
|
+
|
267
|
+
time = parse_now("2006-08-20 03:30:30")
|
268
|
+
assert_equal Time.local(2006, 8, 20, 3, 30, 30), time
|
269
|
+
|
270
|
+
time = parse_now("2006-08-20 15:30:30")
|
271
|
+
assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
|
272
|
+
|
273
|
+
time = parse_now("2006-08-20 15:30.30")
|
274
|
+
assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
|
275
|
+
|
276
|
+
time = parse_now("1902-08-20")
|
277
|
+
assert_equal Time.local(1902, 8, 20, 12, 0, 0), time
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_handle_sm_sy
|
281
|
+
time = parse_now("05/06")
|
282
|
+
assert_equal Time.local(2006, 5, 16, 12), time
|
283
|
+
|
284
|
+
time = parse_now("12/06")
|
285
|
+
assert_equal Time.local(2006, 12, 16, 12), time
|
286
|
+
|
287
|
+
time = parse_now("13/06")
|
288
|
+
assert_equal nil, time
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_handle_r
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_handle_r_g_r
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_handle_srp
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_handle_s_r_p
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_handle_p_s_r
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_handle_s_r_p_a
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_handle_orr
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_handle_o_r_s_r
|
313
|
+
time = parse_now("3rd wednesday in november")
|
314
|
+
assert_equal Time.local(2006, 11, 15, 12), time
|
315
|
+
|
316
|
+
time = parse_now("10th wednesday in november")
|
317
|
+
assert_equal nil, time
|
318
|
+
|
319
|
+
# time = parse_now("3rd wednesday in 2007")
|
320
|
+
# assert_equal Time.local(2007, 1, 20, 12), time
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_handle_o_r_g_r
|
324
|
+
time = parse_now("3rd month next year", :guess => false)
|
325
|
+
assert_equal Time.local(2007, 3), time.begin
|
326
|
+
|
327
|
+
time = parse_now("3rd month next year", :guess => false)
|
328
|
+
assert_equal Time.local(2007, 3, 1), time.begin
|
329
|
+
|
330
|
+
time = parse_now("3rd thursday this september")
|
331
|
+
assert_equal Time.local(2006, 9, 21, 12), time
|
332
|
+
|
333
|
+
now = Time.parse("1/10/2010")
|
334
|
+
time = parse_now("3rd thursday this november", :now => now)
|
335
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
336
|
+
|
337
|
+
time = parse_now("4th day last week")
|
338
|
+
assert_equal Time.local(2006, 8, 9, 12), time
|
339
|
+
end
|
340
|
+
|
341
|
+
# end of testing handlers
|
342
|
+
|
343
|
+
def test_parse_guess_r
|
344
|
+
time = parse_now("friday")
|
345
|
+
assert_equal Time.local(2006, 8, 18, 12), time
|
346
|
+
|
347
|
+
time = parse_now("tue")
|
348
|
+
assert_equal Time.local(2006, 8, 22, 12), time
|
349
|
+
|
350
|
+
time = parse_now("5")
|
351
|
+
assert_equal Time.local(2006, 8, 16, 17), time
|
352
|
+
|
353
|
+
time = Chronic.parse("5", :now => Time.local(2006, 8, 16, 3, 0, 0, 0), :ambiguous_time_range => :none)
|
354
|
+
assert_equal Time.local(2006, 8, 16, 5), time
|
355
|
+
|
356
|
+
time = parse_now("13:00")
|
357
|
+
assert_equal Time.local(2006, 8, 17, 13), time
|
358
|
+
|
359
|
+
time = parse_now("13:45")
|
360
|
+
assert_equal Time.local(2006, 8, 17, 13, 45), time
|
361
|
+
|
362
|
+
time = parse_now("1:01pm")
|
363
|
+
assert_equal Time.local(2006, 8, 16, 13, 01), time
|
364
|
+
|
365
|
+
time = parse_now("2:01pm")
|
366
|
+
assert_equal Time.local(2006, 8, 16, 14, 01), time
|
367
|
+
|
368
|
+
time = parse_now("november")
|
369
|
+
assert_equal Time.local(2006, 11, 16), time
|
370
|
+
end
|
371
|
+
|
372
|
+
def test_parse_guess_rr
|
373
|
+
time = parse_now("friday 13:00")
|
374
|
+
assert_equal Time.local(2006, 8, 18, 13), time
|
375
|
+
|
376
|
+
time = parse_now("monday 4:00")
|
377
|
+
assert_equal Time.local(2006, 8, 21, 16), time
|
378
|
+
|
379
|
+
time = parse_now("sat 4:00", :ambiguous_time_range => :none)
|
380
|
+
assert_equal Time.local(2006, 8, 19, 4), time
|
381
|
+
|
382
|
+
time = parse_now("sunday 4:20", :ambiguous_time_range => :none)
|
383
|
+
assert_equal Time.local(2006, 8, 20, 4, 20), time
|
384
|
+
|
385
|
+
time = parse_now("4 pm")
|
386
|
+
assert_equal Time.local(2006, 8, 16, 16), time
|
387
|
+
|
388
|
+
time = parse_now("4 am", :ambiguous_time_range => :none)
|
389
|
+
assert_equal Time.local(2006, 8, 16, 4), time
|
390
|
+
|
391
|
+
time = parse_now("12 pm")
|
392
|
+
assert_equal Time.local(2006, 8, 16, 12), time
|
393
|
+
|
394
|
+
time = parse_now("12:01 pm")
|
395
|
+
assert_equal Time.local(2006, 8, 16, 12, 1), time
|
396
|
+
|
397
|
+
time = parse_now("12:01 am")
|
398
|
+
assert_equal Time.local(2006, 8, 16, 0, 1), time
|
399
|
+
|
400
|
+
time = parse_now("12 am")
|
401
|
+
assert_equal Time.local(2006, 8, 16), time
|
402
|
+
|
403
|
+
time = parse_now("4:00 in the morning")
|
404
|
+
assert_equal Time.local(2006, 8, 16, 4), time
|
405
|
+
|
406
|
+
time = parse_now("0:10")
|
407
|
+
assert_equal Time.local(2006, 8, 17, 0, 10), time
|
408
|
+
|
409
|
+
time = parse_now("november 4")
|
410
|
+
assert_equal Time.local(2006, 11, 4, 12), time
|
411
|
+
|
412
|
+
time = parse_now("aug 24")
|
413
|
+
assert_equal Time.local(2006, 8, 24, 12), time
|
414
|
+
end
|
415
|
+
|
416
|
+
def test_parse_guess_rrr
|
417
|
+
time = parse_now("friday 1 pm")
|
418
|
+
assert_equal Time.local(2006, 8, 18, 13), time
|
419
|
+
|
420
|
+
time = parse_now("friday 11 at night")
|
421
|
+
assert_equal Time.local(2006, 8, 18, 23), time
|
422
|
+
|
423
|
+
time = parse_now("friday 11 in the evening")
|
424
|
+
assert_equal Time.local(2006, 8, 18, 23), time
|
425
|
+
|
426
|
+
time = parse_now("sunday 6am")
|
427
|
+
assert_equal Time.local(2006, 8, 20, 6), time
|
428
|
+
|
429
|
+
time = parse_now("friday evening at 7")
|
430
|
+
assert_equal Time.local(2006, 8, 18, 19), time
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_parse_guess_gr
|
434
|
+
# year
|
435
|
+
|
436
|
+
time = parse_now("this year", :guess => false)
|
437
|
+
assert_equal Time.local(2006, 8, 17), time.begin
|
438
|
+
|
439
|
+
time = parse_now("this year", :context => :past, :guess => false)
|
440
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
441
|
+
|
442
|
+
# month
|
443
|
+
|
444
|
+
time = parse_now("this month")
|
445
|
+
assert_equal Time.local(2006, 8, 24, 12), time
|
446
|
+
|
447
|
+
time = parse_now("this month", :context => :past)
|
448
|
+
assert_equal Time.local(2006, 8, 8, 12), time
|
449
|
+
|
450
|
+
time = Chronic.parse("next month", :now => Time.local(2006, 11, 15))
|
451
|
+
assert_equal Time.local(2006, 12, 16, 12), time
|
452
|
+
|
453
|
+
# month name
|
454
|
+
|
455
|
+
time = parse_now("last november")
|
456
|
+
assert_equal Time.local(2005, 11, 16), time
|
457
|
+
|
458
|
+
# fortnight
|
459
|
+
|
460
|
+
time = parse_now("this fortnight")
|
461
|
+
assert_equal Time.local(2006, 8, 21, 19, 30), time
|
462
|
+
|
463
|
+
time = parse_now("this fortnight", :context => :past)
|
464
|
+
assert_equal Time.local(2006, 8, 14, 19), time
|
465
|
+
|
466
|
+
# week
|
467
|
+
|
468
|
+
time = parse_now("this week")
|
469
|
+
assert_equal Time.local(2006, 8, 18, 7, 30), time
|
470
|
+
|
471
|
+
time = parse_now("this week", :context => :past)
|
472
|
+
assert_equal Time.local(2006, 8, 14, 19), time
|
473
|
+
|
474
|
+
# weekend
|
475
|
+
|
476
|
+
time = parse_now("this weekend")
|
477
|
+
assert_equal Time.local(2006, 8, 20), time
|
478
|
+
|
479
|
+
time = parse_now("this weekend", :context => :past)
|
480
|
+
assert_equal Time.local(2006, 8, 13), time
|
481
|
+
|
482
|
+
time = parse_now("last weekend")
|
483
|
+
assert_equal Time.local(2006, 8, 13), time
|
484
|
+
|
485
|
+
# day
|
486
|
+
|
487
|
+
time = parse_now("this day")
|
488
|
+
assert_equal Time.local(2006, 8, 16, 19), time
|
489
|
+
|
490
|
+
time = parse_now("this day", :context => :past)
|
491
|
+
assert_equal Time.local(2006, 8, 16, 7), time
|
492
|
+
|
493
|
+
time = parse_now("today")
|
494
|
+
assert_equal Time.local(2006, 8, 16, 19), time
|
495
|
+
|
496
|
+
time = parse_now("yesterday")
|
497
|
+
assert_equal Time.local(2006, 8, 15, 12), time
|
498
|
+
|
499
|
+
now = Time.parse("2011-05-27 23:10") # after 11pm
|
500
|
+
time = parse_now("yesterday", :now => now)
|
501
|
+
assert_equal Time.local(2011, 05, 26, 12), time
|
502
|
+
|
503
|
+
time = parse_now("tomorrow")
|
504
|
+
assert_equal Time.local(2006, 8, 17, 12), time
|
505
|
+
|
506
|
+
# day name
|
507
|
+
|
508
|
+
time = parse_now("this tuesday")
|
509
|
+
assert_equal Time.local(2006, 8, 22, 12), time
|
510
|
+
|
511
|
+
time = parse_now("next tuesday")
|
512
|
+
assert_equal Time.local(2006, 8, 22, 12), time
|
513
|
+
|
514
|
+
time = parse_now("last tuesday")
|
515
|
+
assert_equal Time.local(2006, 8, 15, 12), time
|
516
|
+
|
517
|
+
time = parse_now("this wed")
|
518
|
+
assert_equal Time.local(2006, 8, 23, 12), time
|
519
|
+
|
520
|
+
time = parse_now("next wed")
|
521
|
+
assert_equal Time.local(2006, 8, 23, 12), time
|
522
|
+
|
523
|
+
time = parse_now("last wed")
|
524
|
+
assert_equal Time.local(2006, 8, 9, 12), time
|
525
|
+
|
526
|
+
# day portion
|
527
|
+
|
528
|
+
time = parse_now("this morning")
|
529
|
+
assert_equal Time.local(2006, 8, 16, 9), time
|
530
|
+
|
531
|
+
time = parse_now("tonight")
|
532
|
+
assert_equal Time.local(2006, 8, 16, 22), time
|
533
|
+
|
534
|
+
# minute
|
535
|
+
|
536
|
+
time = parse_now("next minute")
|
537
|
+
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
538
|
+
|
539
|
+
# second
|
540
|
+
|
541
|
+
time = parse_now("this second")
|
542
|
+
assert_equal Time.local(2006, 8, 16, 14), time
|
543
|
+
|
544
|
+
time = parse_now("this second", :context => :past)
|
545
|
+
assert_equal Time.local(2006, 8, 16, 14), time
|
546
|
+
|
547
|
+
time = parse_now("next second")
|
548
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
|
549
|
+
|
550
|
+
time = parse_now("last second")
|
551
|
+
assert_equal Time.local(2006, 8, 16, 13, 59, 59), time
|
552
|
+
end
|
553
|
+
|
554
|
+
def test_parse_guess_grr
|
555
|
+
time = parse_now("yesterday at 4:00")
|
556
|
+
assert_equal Time.local(2006, 8, 15, 16), time
|
557
|
+
|
558
|
+
time = parse_now("today at 9:00")
|
559
|
+
assert_equal Time.local(2006, 8, 16, 9), time
|
560
|
+
|
561
|
+
time = parse_now("today at 2100")
|
562
|
+
assert_equal Time.local(2006, 8, 16, 21), time
|
563
|
+
|
564
|
+
time = parse_now("this day at 0900")
|
565
|
+
assert_equal Time.local(2006, 8, 16, 9), time
|
566
|
+
|
567
|
+
time = parse_now("tomorrow at 0900")
|
568
|
+
assert_equal Time.local(2006, 8, 17, 9), time
|
569
|
+
|
570
|
+
time = parse_now("yesterday at 4:00", :ambiguous_time_range => :none)
|
571
|
+
assert_equal Time.local(2006, 8, 15, 4), time
|
572
|
+
|
573
|
+
time = parse_now("last friday at 4:00")
|
574
|
+
assert_equal Time.local(2006, 8, 11, 16), time
|
575
|
+
|
576
|
+
time = parse_now("next wed 4:00")
|
577
|
+
assert_equal Time.local(2006, 8, 23, 16), time
|
578
|
+
|
579
|
+
time = parse_now("yesterday afternoon")
|
580
|
+
assert_equal Time.local(2006, 8, 15, 15), time
|
581
|
+
|
582
|
+
time = parse_now("last week tuesday")
|
583
|
+
assert_equal Time.local(2006, 8, 8, 12), time
|
584
|
+
|
585
|
+
time = parse_now("tonight at 7")
|
586
|
+
assert_equal Time.local(2006, 8, 16, 19), time
|
587
|
+
|
588
|
+
time = parse_now("tonight 7")
|
589
|
+
assert_equal Time.local(2006, 8, 16, 19), time
|
590
|
+
|
591
|
+
time = parse_now("7 tonight")
|
592
|
+
assert_equal Time.local(2006, 8, 16, 19), time
|
593
|
+
end
|
594
|
+
|
595
|
+
def test_parse_guess_grrr
|
596
|
+
time = parse_now("today at 6:00pm")
|
597
|
+
assert_equal Time.local(2006, 8, 16, 18), time
|
598
|
+
|
599
|
+
time = parse_now("today at 6:00am")
|
600
|
+
assert_equal Time.local(2006, 8, 16, 6), time
|
601
|
+
|
602
|
+
time = parse_now("this day 1800")
|
603
|
+
assert_equal Time.local(2006, 8, 16, 18), time
|
604
|
+
|
605
|
+
time = parse_now("yesterday at 4:00pm")
|
606
|
+
assert_equal Time.local(2006, 8, 15, 16), time
|
607
|
+
|
608
|
+
time = parse_now("tomorrow evening at 7")
|
609
|
+
assert_equal Time.local(2006, 8, 17, 19), time
|
610
|
+
|
611
|
+
time = parse_now("tomorrow morning at 5:30")
|
612
|
+
assert_equal Time.local(2006, 8, 17, 5, 30), time
|
613
|
+
|
614
|
+
time = parse_now("next monday at 12:01 am")
|
615
|
+
assert_equal Time.local(2006, 8, 21, 00, 1), time
|
616
|
+
|
617
|
+
time = parse_now("next monday at 12:01 pm")
|
618
|
+
assert_equal Time.local(2006, 8, 21, 12, 1), time
|
619
|
+
|
620
|
+
# with context
|
621
|
+
time = parse_now("sunday at 8:15pm", :context => :past)
|
622
|
+
assert_equal Time.local(2006, 8, 13, 20, 15), time
|
623
|
+
end
|
624
|
+
|
625
|
+
def test_parse_guess_rgr
|
626
|
+
time = parse_now("afternoon yesterday")
|
627
|
+
assert_equal Time.local(2006, 8, 15, 15), time
|
628
|
+
|
629
|
+
time = parse_now("tuesday last week")
|
630
|
+
assert_equal Time.local(2006, 8, 8, 12), time
|
631
|
+
end
|
632
|
+
|
633
|
+
def test_parse_guess_s_r_p
|
634
|
+
# past
|
635
|
+
|
636
|
+
time = parse_now("3 years ago")
|
637
|
+
assert_equal Time.local(2003, 8, 16, 14), time
|
638
|
+
|
639
|
+
time = parse_now("1 month ago")
|
640
|
+
assert_equal Time.local(2006, 7, 16, 14), time
|
641
|
+
|
642
|
+
time = parse_now("1 fortnight ago")
|
643
|
+
assert_equal Time.local(2006, 8, 2, 14), time
|
644
|
+
|
645
|
+
time = parse_now("2 fortnights ago")
|
646
|
+
assert_equal Time.local(2006, 7, 19, 14), time
|
647
|
+
|
648
|
+
time = parse_now("3 weeks ago")
|
649
|
+
assert_equal Time.local(2006, 7, 26, 14), time
|
650
|
+
|
651
|
+
time = parse_now("2 weekends ago")
|
652
|
+
assert_equal Time.local(2006, 8, 5), time
|
653
|
+
|
654
|
+
time = parse_now("3 days ago")
|
655
|
+
assert_equal Time.local(2006, 8, 13, 14), time
|
656
|
+
|
657
|
+
#time = parse_now("1 monday ago")
|
658
|
+
#assert_equal Time.local(2006, 8, 14, 12), time
|
659
|
+
|
660
|
+
time = parse_now("5 mornings ago")
|
661
|
+
assert_equal Time.local(2006, 8, 12, 9), time
|
662
|
+
|
663
|
+
time = parse_now("7 hours ago")
|
664
|
+
assert_equal Time.local(2006, 8, 16, 7), time
|
665
|
+
|
666
|
+
time = parse_now("3 minutes ago")
|
667
|
+
assert_equal Time.local(2006, 8, 16, 13, 57), time
|
668
|
+
|
669
|
+
time = parse_now("20 seconds before now")
|
670
|
+
assert_equal Time.local(2006, 8, 16, 13, 59, 40), time
|
671
|
+
|
672
|
+
# future
|
673
|
+
|
674
|
+
time = parse_now("3 years from now")
|
675
|
+
assert_equal Time.local(2009, 8, 16, 14, 0, 0), time
|
676
|
+
|
677
|
+
time = parse_now("6 months hence")
|
678
|
+
assert_equal Time.local(2007, 2, 16, 14), time
|
679
|
+
|
680
|
+
time = parse_now("3 fortnights hence")
|
681
|
+
assert_equal Time.local(2006, 9, 27, 14), time
|
682
|
+
|
683
|
+
time = parse_now("1 week from now")
|
684
|
+
assert_equal Time.local(2006, 8, 23, 14, 0, 0), time
|
685
|
+
|
686
|
+
time = parse_now("1 weekend from now")
|
687
|
+
assert_equal Time.local(2006, 8, 19), time
|
688
|
+
|
689
|
+
time = parse_now("2 weekends from now")
|
690
|
+
assert_equal Time.local(2006, 8, 26), time
|
691
|
+
|
692
|
+
time = parse_now("1 day hence")
|
693
|
+
assert_equal Time.local(2006, 8, 17, 14), time
|
694
|
+
|
695
|
+
time = parse_now("5 mornings hence")
|
696
|
+
assert_equal Time.local(2006, 8, 21, 9), time
|
697
|
+
|
698
|
+
time = parse_now("1 hour from now")
|
699
|
+
assert_equal Time.local(2006, 8, 16, 15), time
|
700
|
+
|
701
|
+
time = parse_now("20 minutes hence")
|
702
|
+
assert_equal Time.local(2006, 8, 16, 14, 20), time
|
703
|
+
|
704
|
+
time = parse_now("20 seconds from now")
|
705
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 20), time
|
706
|
+
|
707
|
+
time = Chronic.parse("2 months ago", :now => Time.parse("2007-03-07 23:30"))
|
708
|
+
assert_equal Time.local(2007, 1, 7, 23, 30), time
|
709
|
+
end
|
710
|
+
|
711
|
+
def test_parse_guess_p_s_r
|
712
|
+
time = parse_now("in 3 hours")
|
713
|
+
assert_equal Time.local(2006, 8, 16, 17), time
|
714
|
+
end
|
715
|
+
|
716
|
+
def test_parse_guess_s_r_p_a
|
717
|
+
# past
|
718
|
+
|
719
|
+
time = parse_now("3 years ago tomorrow")
|
720
|
+
assert_equal Time.local(2003, 8, 17, 12), time
|
721
|
+
|
722
|
+
time = parse_now("3 years ago this friday")
|
723
|
+
assert_equal Time.local(2003, 8, 18, 12), time
|
724
|
+
|
725
|
+
time = parse_now("3 months ago saturday at 5:00 pm")
|
726
|
+
assert_equal Time.local(2006, 5, 19, 17), time
|
727
|
+
|
728
|
+
time = parse_now("2 days from this second")
|
729
|
+
assert_equal Time.local(2006, 8, 18, 14), time
|
730
|
+
|
731
|
+
time = parse_now("7 hours before tomorrow at midnight")
|
732
|
+
assert_equal Time.local(2006, 8, 17, 17), time
|
733
|
+
|
734
|
+
# future
|
735
|
+
end
|
736
|
+
|
737
|
+
def test_parse_guess_o_r_g_r
|
738
|
+
time = parse_now("3rd month next year", :guess => false)
|
739
|
+
assert_equal Time.local(2007, 3), time.begin
|
740
|
+
|
741
|
+
time = parse_now("3rd month next year", :guess => false)
|
742
|
+
assert_equal Time.local(2007, 3, 1), time.begin
|
743
|
+
|
744
|
+
time = parse_now("3rd thursday this september")
|
745
|
+
assert_equal Time.local(2006, 9, 21, 12), time
|
746
|
+
|
747
|
+
now = Time.parse("1/10/2010")
|
748
|
+
time = parse_now("3rd thursday this november", :now => now)
|
749
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
750
|
+
|
751
|
+
time = parse_now("4th day last week")
|
752
|
+
assert_equal Time.local(2006, 8, 9, 12), time
|
753
|
+
end
|
754
|
+
|
755
|
+
def test_parse_guess_nonsense
|
756
|
+
time = parse_now("some stupid nonsense")
|
757
|
+
assert_equal nil, time
|
758
|
+
|
759
|
+
time = parse_now("Ham Sandwich")
|
760
|
+
assert_equal nil, time
|
761
|
+
end
|
762
|
+
|
763
|
+
def test_parse_span
|
764
|
+
span = parse_now("friday", :guess => false)
|
765
|
+
assert_equal Time.local(2006, 8, 18), span.begin
|
766
|
+
assert_equal Time.local(2006, 8, 19), span.end
|
767
|
+
|
768
|
+
span = parse_now("november", :guess => false)
|
769
|
+
assert_equal Time.local(2006, 11), span.begin
|
770
|
+
assert_equal Time.local(2006, 12), span.end
|
771
|
+
|
772
|
+
span = Chronic.parse("weekend" , :now => @time_2006_08_16_14_00_00, :guess => false)
|
773
|
+
assert_equal Time.local(2006, 8, 19), span.begin
|
774
|
+
assert_equal Time.local(2006, 8, 21), span.end
|
775
|
+
end
|
776
|
+
|
777
|
+
def test_parse_with_endian_precedence
|
778
|
+
date = '11/02/2007'
|
779
|
+
|
780
|
+
expect_for_middle_endian = Time.local(2007, 11, 2, 12)
|
781
|
+
expect_for_little_endian = Time.local(2007, 2, 11, 12)
|
782
|
+
|
783
|
+
# default precedence should be toward middle endianness
|
784
|
+
assert_equal expect_for_middle_endian, Chronic.parse(date)
|
785
|
+
|
786
|
+
assert_equal expect_for_middle_endian, Chronic.parse(date, :endian_precedence => [:middle, :little])
|
787
|
+
|
788
|
+
assert_equal expect_for_little_endian, Chronic.parse(date, :endian_precedence => [:little, :middle])
|
789
|
+
end
|
790
|
+
|
791
|
+
def test_parse_words
|
792
|
+
assert_equal parse_now("33 days from now"), parse_now("thirty-three days from now")
|
793
|
+
assert_equal parse_now("2867532 seconds from now"), parse_now("two million eight hundred and sixty seven thousand five hundred and thirty two seconds from now")
|
794
|
+
assert_equal parse_now("may 10th"), parse_now("may tenth")
|
795
|
+
end
|
796
|
+
|
797
|
+
def test_parse_only_complete_pointers
|
798
|
+
assert_equal parse_now("eat pasty buns today at 2pm"), @time_2006_08_16_14_00_00
|
799
|
+
assert_equal parse_now("futuristically speaking today at 2pm"), @time_2006_08_16_14_00_00
|
800
|
+
assert_equal parse_now("meeting today at 2pm"), @time_2006_08_16_14_00_00
|
801
|
+
end
|
802
|
+
|
803
|
+
def test_am_pm
|
804
|
+
assert_equal Time.local(2006, 8, 16), parse_now("8/16/2006 at 12am")
|
805
|
+
assert_equal Time.local(2006, 8, 16, 12), parse_now("8/16/2006 at 12pm")
|
806
|
+
end
|
807
|
+
|
808
|
+
def test_a_p
|
809
|
+
assert_equal Time.local(2006, 8, 16, 0, 15), parse_now("8/16/2006 at 12:15a")
|
810
|
+
assert_equal Time.local(2006, 8, 16, 18, 30), parse_now("8/16/2006 at 6:30p")
|
811
|
+
end
|
812
|
+
|
813
|
+
def test_argument_validation
|
814
|
+
assert_raise(ArgumentError) do
|
815
|
+
time = Chronic.parse("may 27", :foo => :bar)
|
816
|
+
end
|
817
|
+
|
818
|
+
assert_raise(ArgumentError) do
|
819
|
+
time = Chronic.parse("may 27", :context => :bar)
|
820
|
+
end
|
821
|
+
end
|
822
|
+
|
823
|
+
def test_seasons
|
824
|
+
t = parse_now("this spring", :guess => false)
|
825
|
+
assert_equal Time.local(2007, 3, 20), t.begin
|
826
|
+
assert_equal Time.local(2007, 6, 20), t.end
|
827
|
+
|
828
|
+
t = parse_now("this winter", :guess => false)
|
829
|
+
assert_equal Time.local(2006, 12, 22), t.begin
|
830
|
+
assert_equal Time.local(2007, 3, 19), t.end
|
831
|
+
|
832
|
+
t = parse_now("last spring", :guess => false)
|
833
|
+
assert_equal Time.local(2006, 3, 20), t.begin
|
834
|
+
assert_equal Time.local(2006, 6, 20), t.end
|
835
|
+
|
836
|
+
t = parse_now("last winter", :guess => false)
|
837
|
+
assert_equal Time.local(2005, 12, 22), t.begin
|
838
|
+
assert_equal Time.local(2006, 3, 19), t.end
|
839
|
+
|
840
|
+
t = parse_now("next spring", :guess => false)
|
841
|
+
assert_equal Time.local(2007, 3, 20), t.begin
|
842
|
+
assert_equal Time.local(2007, 6, 20), t.end
|
843
|
+
end
|
844
|
+
|
845
|
+
# regression
|
846
|
+
|
847
|
+
# def test_partial
|
848
|
+
# assert_equal '', parse_now("2 hours")
|
849
|
+
# end
|
850
|
+
|
851
|
+
def test_days_in_november
|
852
|
+
t1 = Chronic.parse('1st thursday in november', :now => Time.local(2007))
|
853
|
+
assert_equal Time.local(2007, 11, 1, 12), t1
|
854
|
+
|
855
|
+
t1 = Chronic.parse('1st friday in november', :now => Time.local(2007))
|
856
|
+
assert_equal Time.local(2007, 11, 2, 12), t1
|
857
|
+
|
858
|
+
t1 = Chronic.parse('1st saturday in november', :now => Time.local(2007))
|
859
|
+
assert_equal Time.local(2007, 11, 3, 12), t1
|
860
|
+
|
861
|
+
# t1 = Chronic.parse('1st sunday in november', :now => Time.local(2007))
|
862
|
+
# assert_equal Time.local(2007, 11, 4, 12), t1
|
863
|
+
|
864
|
+
# Chronic.debug = true
|
865
|
+
#
|
866
|
+
# t1 = Chronic.parse('1st monday in november', :now => Time.local(2007))
|
867
|
+
# assert_equal Time.local(2007, 11, 5, 11), t1
|
868
|
+
end
|
869
|
+
|
870
|
+
def test_now_changes
|
871
|
+
t1 = Chronic.parse("now")
|
872
|
+
sleep 0.1
|
873
|
+
t2 = Chronic.parse("now")
|
874
|
+
assert_not_equal t1, t2
|
875
|
+
end
|
876
|
+
|
877
|
+
def test_noon
|
878
|
+
t1 = Chronic.parse('2011-01-01 at noon', :ambiguous_time_range => :none)
|
879
|
+
assert_equal Time.local(2011, 1, 1, 12, 0), t1
|
880
|
+
end
|
881
|
+
|
882
|
+
private
|
883
|
+
def parse_now(string, options={})
|
884
|
+
Chronic.parse(string, {:now => TIME_2006_08_16_14_00_00 }.merge(options))
|
885
|
+
end
|
886
|
+
end
|