Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 712 lines (486 sloc) 21.79 kB
da3a121 @mojombo added pre-existing codebase
mojombo authored
1 require 'chronic'
2 require 'test/unit'
3
4 class TestParsing < Test::Unit::TestCase
044fbd7 @mojombo numerizer, time overflow
mojombo authored
5 # Wed Aug 16 14:00:00 UTC 2006
6 TIME_2006_08_16_14_00_00 = Time.local(2006, 8, 16, 14, 0, 0, 0)
da3a121 @mojombo added pre-existing codebase
mojombo authored
7
8 def setup
044fbd7 @mojombo numerizer, time overflow
mojombo authored
9 @time_2006_08_16_14_00_00 = TIME_2006_08_16_14_00_00
da3a121 @mojombo added pre-existing codebase
mojombo authored
10 end
11
044fbd7 @mojombo numerizer, time overflow
mojombo authored
12 def test_parse_guess_dates
da3a121 @mojombo added pre-existing codebase
mojombo authored
13 # rm_sd
14
044fbd7 @mojombo numerizer, time overflow
mojombo authored
15 time = parse_now("may 27")
da3a121 @mojombo added pre-existing codebase
mojombo authored
16 assert_equal Time.local(2007, 5, 27, 12), time
17
044fbd7 @mojombo numerizer, time overflow
mojombo authored
18 time = parse_now("may 28", :context => :past)
da3a121 @mojombo added pre-existing codebase
mojombo authored
19 assert_equal Time.local(2006, 5, 28, 12), time
20
044fbd7 @mojombo numerizer, time overflow
mojombo authored
21 time = parse_now("may 28 5pm", :context => :past)
da3a121 @mojombo added pre-existing codebase
mojombo authored
22 assert_equal Time.local(2006, 5, 28, 17), time
23
044fbd7 @mojombo numerizer, time overflow
mojombo authored
24 time = parse_now("may 28 at 5pm", :context => :past)
da3a121 @mojombo added pre-existing codebase
mojombo authored
25 assert_equal Time.local(2006, 5, 28, 17), time
26
044fbd7 @mojombo numerizer, time overflow
mojombo authored
27 time = parse_now("may 28 at 5:32.19pm", :context => :past)
7f3625b @mojombo bug fixes, seconds for all dates, hoe
mojombo authored
28 assert_equal Time.local(2006, 5, 28, 17, 32, 19), time
29
2dd9143 Add handler for '5pm on May 27' and the like
indirect authored
30 # rm_sd_on
31
32 time = parse_now("5pm on may 28")
33 assert_equal Time.local(2007, 5, 28, 17), time
34
35 time = parse_now("5pm may 28")
36 assert_equal Time.local(2007, 5, 28, 17), time
37
38 time = parse_now("5 on may 28", :ambiguous_time_range => :none)
39 assert_equal Time.local(2007, 5, 28, 05), time
40
da3a121 @mojombo added pre-existing codebase
mojombo authored
41 # rm_od
42
044fbd7 @mojombo numerizer, time overflow
mojombo authored
43 time = parse_now("may 27th")
da3a121 @mojombo added pre-existing codebase
mojombo authored
44 assert_equal Time.local(2007, 5, 27, 12), time
45
044fbd7 @mojombo numerizer, time overflow
mojombo authored
46 time = parse_now("may 27th", :context => :past)
da3a121 @mojombo added pre-existing codebase
mojombo authored
47 assert_equal Time.local(2006, 5, 27, 12), time
48
044fbd7 @mojombo numerizer, time overflow
mojombo authored
49 time = parse_now("may 27th 5:00 pm", :context => :past)
da3a121 @mojombo added pre-existing codebase
mojombo authored
50 assert_equal Time.local(2006, 5, 27, 17), time
51
044fbd7 @mojombo numerizer, time overflow
mojombo authored
52 time = parse_now("may 27th at 5pm", :context => :past)
da3a121 @mojombo added pre-existing codebase
mojombo authored
53 assert_equal Time.local(2006, 5, 27, 17), time
54
044fbd7 @mojombo numerizer, time overflow
mojombo authored
55 time = parse_now("may 27th at 5", :ambiguous_time_range => :none)
da3a121 @mojombo added pre-existing codebase
mojombo authored
56 assert_equal Time.local(2007, 5, 27, 5), time
57
2dd9143 Add handler for '5pm on May 27' and the like
indirect authored
58 # rm_od_on
59
60 time = parse_now("5:00 pm may 27th", :context => :past)
61 assert_equal Time.local(2006, 5, 27, 17), time
62
63 time = parse_now("5pm on may 27th", :context => :past)
64 assert_equal Time.local(2006, 5, 27, 17), time
65
66 time = parse_now("5 on may 27th", :ambiguous_time_range => :none)
67 assert_equal Time.local(2007, 5, 27, 5), time
68
da3a121 @mojombo added pre-existing codebase
mojombo authored
69 # rm_sy
70
044fbd7 @mojombo numerizer, time overflow
mojombo authored
71 time = parse_now("June 1979")
da3a121 @mojombo added pre-existing codebase
mojombo authored
72 assert_equal Time.local(1979, 6, 16, 0), time
73
044fbd7 @mojombo numerizer, time overflow
mojombo authored
74 time = parse_now("dec 79")
da3a121 @mojombo added pre-existing codebase
mojombo authored
75 assert_equal Time.local(1979, 12, 16, 12), time
76
77 # rm_sd_sy
78
044fbd7 @mojombo numerizer, time overflow
mojombo authored
79 time = parse_now("jan 3 2010")
da3a121 @mojombo added pre-existing codebase
mojombo authored
80 assert_equal Time.local(2010, 1, 3, 12), time
81
044fbd7 @mojombo numerizer, time overflow
mojombo authored
82 time = parse_now("jan 3 2010 midnight")
da3a121 @mojombo added pre-existing codebase
mojombo authored
83 assert_equal Time.local(2010, 1, 4, 0), time
84
044fbd7 @mojombo numerizer, time overflow
mojombo authored
85 time = parse_now("jan 3 2010 at midnight")
da3a121 @mojombo added pre-existing codebase
mojombo authored
86 assert_equal Time.local(2010, 1, 4, 0), time
87
044fbd7 @mojombo numerizer, time overflow
mojombo authored
88 time = parse_now("jan 3 2010 at 4", :ambiguous_time_range => :none)
da3a121 @mojombo added pre-existing codebase
mojombo authored
89 assert_equal Time.local(2010, 1, 3, 4), time
90
044fbd7 @mojombo numerizer, time overflow
mojombo authored
91 #time = parse_now("January 12, '00")
da3a121 @mojombo added pre-existing codebase
mojombo authored
92 #assert_equal Time.local(2000, 1, 12, 12), time
93
79527a3 @mojombo fix numerizer bugs
mojombo authored
94 time = parse_now("may 27, 1979")
95 assert_equal Time.local(1979, 5, 27, 12), time
96
044fbd7 @mojombo numerizer, time overflow
mojombo authored
97 time = parse_now("may 27 79")
da3a121 @mojombo added pre-existing codebase
mojombo authored
98 assert_equal Time.local(1979, 5, 27, 12), time
99
044fbd7 @mojombo numerizer, time overflow
mojombo authored
100 time = parse_now("may 27 79 4:30")
da3a121 @mojombo added pre-existing codebase
mojombo authored
101 assert_equal Time.local(1979, 5, 27, 16, 30), time
102
044fbd7 @mojombo numerizer, time overflow
mojombo authored
103 time = parse_now("may 27 79 at 4:30", :ambiguous_time_range => :none)
da3a121 @mojombo added pre-existing codebase
mojombo authored
104 assert_equal Time.local(1979, 5, 27, 4, 30), time
105
106 # sd_rm_sy
107
044fbd7 @mojombo numerizer, time overflow
mojombo authored
108 time = parse_now("3 jan 2010")
da3a121 @mojombo added pre-existing codebase
mojombo authored
109 assert_equal Time.local(2010, 1, 3, 12), time
110
044fbd7 @mojombo numerizer, time overflow
mojombo authored
111 time = parse_now("3 jan 2010 4pm")
da3a121 @mojombo added pre-existing codebase
mojombo authored
112 assert_equal Time.local(2010, 1, 3, 16), time
113
79527a3 @mojombo fix numerizer bugs
mojombo authored
114 time = parse_now("27 Oct 2006 7:30pm")
115 assert_equal Time.local(2006, 10, 27, 19, 30), time
116
da3a121 @mojombo added pre-existing codebase
mojombo authored
117 # sm_sd_sy
118
044fbd7 @mojombo numerizer, time overflow
mojombo authored
119 time = parse_now("5/27/1979")
da3a121 @mojombo added pre-existing codebase
mojombo authored
120 assert_equal Time.local(1979, 5, 27, 12), time
121
044fbd7 @mojombo numerizer, time overflow
mojombo authored
122 time = parse_now("5/27/1979 4am")
da3a121 @mojombo added pre-existing codebase
mojombo authored
123 assert_equal Time.local(1979, 5, 27, 4), time
124
125 # sd_sm_sy
126
044fbd7 @mojombo numerizer, time overflow
mojombo authored
127 time = parse_now("27/5/1979")
da3a121 @mojombo added pre-existing codebase
mojombo authored
128 assert_equal Time.local(1979, 5, 27, 12), time
129
044fbd7 @mojombo numerizer, time overflow
mojombo authored
130 time = parse_now("27/5/1979 @ 0700")
da3a121 @mojombo added pre-existing codebase
mojombo authored
131 assert_equal Time.local(1979, 5, 27, 7), time
132
133 # sm_sy
134
044fbd7 @mojombo numerizer, time overflow
mojombo authored
135 time = parse_now("05/06")
da3a121 @mojombo added pre-existing codebase
mojombo authored
136 assert_equal Time.local(2006, 5, 16, 12), time
137
044fbd7 @mojombo numerizer, time overflow
mojombo authored
138 time = parse_now("12/06")
da3a121 @mojombo added pre-existing codebase
mojombo authored
139 assert_equal Time.local(2006, 12, 16, 12), time
140
044fbd7 @mojombo numerizer, time overflow
mojombo authored
141 time = parse_now("13/06")
da3a121 @mojombo added pre-existing codebase
mojombo authored
142 assert_equal nil, time
143
144 # sy_sm_sd
145
044fbd7 @mojombo numerizer, time overflow
mojombo authored
146 time = parse_now("2000-1-1")
da3a121 @mojombo added pre-existing codebase
mojombo authored
147 assert_equal Time.local(2000, 1, 1, 12), time
148
044fbd7 @mojombo numerizer, time overflow
mojombo authored
149 time = parse_now("2006-08-20")
da3a121 @mojombo added pre-existing codebase
mojombo authored
150 assert_equal Time.local(2006, 8, 20, 12), time
151
044fbd7 @mojombo numerizer, time overflow
mojombo authored
152 time = parse_now("2006-08-20 7pm")
da3a121 @mojombo added pre-existing codebase
mojombo authored
153 assert_equal Time.local(2006, 8, 20, 19), time
154
044fbd7 @mojombo numerizer, time overflow
mojombo authored
155 time = parse_now("2006-08-20 03:00")
da3a121 @mojombo added pre-existing codebase
mojombo authored
156 assert_equal Time.local(2006, 8, 20, 3), time
157
044fbd7 @mojombo numerizer, time overflow
mojombo authored
158 time = parse_now("2006-08-20 03:30:30")
7f3625b @mojombo bug fixes, seconds for all dates, hoe
mojombo authored
159 assert_equal Time.local(2006, 8, 20, 3, 30, 30), time
160
044fbd7 @mojombo numerizer, time overflow
mojombo authored
161 time = parse_now("2006-08-20 15:30:30")
7f3625b @mojombo bug fixes, seconds for all dates, hoe
mojombo authored
162 assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
163
044fbd7 @mojombo numerizer, time overflow
mojombo authored
164 time = parse_now("2006-08-20 15:30.30")
7f3625b @mojombo bug fixes, seconds for all dates, hoe
mojombo authored
165 assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
166
f4fef51 @mojombo svrc updates
mojombo authored
167 # rdn_rm_rd_rt_rtz_ry
168
169 time = parse_now("Mon Apr 02 17:00:00 PDT 2007")
79527a3 @mojombo fix numerizer bugs
mojombo authored
170 assert_equal 1175558400, time.to_i
f4fef51 @mojombo svrc updates
mojombo authored
171
172 now = Time.now
173 time = parse_now(now.to_s)
174 assert_equal now.to_s, time.to_s
175
da3a121 @mojombo added pre-existing codebase
mojombo authored
176 # rm_sd_rt
177
044fbd7 @mojombo numerizer, time overflow
mojombo authored
178 #time = parse_now("jan 5 13:00")
da3a121 @mojombo added pre-existing codebase
mojombo authored
179 #assert_equal Time.local(2007, 1, 5, 13), time
180
181 # due to limitations of the Time class, these don't work
182
044fbd7 @mojombo numerizer, time overflow
mojombo authored
183 time = parse_now("may 40")
da3a121 @mojombo added pre-existing codebase
mojombo authored
184 assert_equal nil, time
185
044fbd7 @mojombo numerizer, time overflow
mojombo authored
186 time = parse_now("may 27 40")
da3a121 @mojombo added pre-existing codebase
mojombo authored
187 assert_equal nil, time
188
044fbd7 @mojombo numerizer, time overflow
mojombo authored
189 time = parse_now("1800-08-20")
da3a121 @mojombo added pre-existing codebase
mojombo authored
190 assert_equal nil, time
191 end
f4fef51 @mojombo svrc updates
mojombo authored
192
da3a121 @mojombo added pre-existing codebase
mojombo authored
193 def test_parse_guess_r
044fbd7 @mojombo numerizer, time overflow
mojombo authored
194 time = parse_now("friday")
da3a121 @mojombo added pre-existing codebase
mojombo authored
195 assert_equal Time.local(2006, 8, 18, 12), time
196
f4fef51 @mojombo svrc updates
mojombo authored
197 time = parse_now("tue")
198 assert_equal Time.local(2006, 8, 22, 12), time
199
044fbd7 @mojombo numerizer, time overflow
mojombo authored
200 time = parse_now("5")
da3a121 @mojombo added pre-existing codebase
mojombo authored
201 assert_equal Time.local(2006, 8, 16, 17), time
202
044fbd7 @mojombo numerizer, time overflow
mojombo authored
203 time = Chronic.parse("5", :now => Time.local(2006, 8, 16, 3, 0, 0, 0), :ambiguous_time_range => :none)
da3a121 @mojombo added pre-existing codebase
mojombo authored
204 assert_equal Time.local(2006, 8, 16, 5), time
205
044fbd7 @mojombo numerizer, time overflow
mojombo authored
206 time = parse_now("13:00")
da3a121 @mojombo added pre-existing codebase
mojombo authored
207 assert_equal Time.local(2006, 8, 17, 13), time
208
044fbd7 @mojombo numerizer, time overflow
mojombo authored
209 time = parse_now("13:45")
da3a121 @mojombo added pre-existing codebase
mojombo authored
210 assert_equal Time.local(2006, 8, 17, 13, 45), time
211
044fbd7 @mojombo numerizer, time overflow
mojombo authored
212 time = parse_now("november")
da3a121 @mojombo added pre-existing codebase
mojombo authored
213 assert_equal Time.local(2006, 11, 16), time
214 end
215
216 def test_parse_guess_rr
044fbd7 @mojombo numerizer, time overflow
mojombo authored
217 time = parse_now("friday 13:00")
da3a121 @mojombo added pre-existing codebase
mojombo authored
218 assert_equal Time.local(2006, 8, 18, 13), time
219
044fbd7 @mojombo numerizer, time overflow
mojombo authored
220 time = parse_now("monday 4:00")
da3a121 @mojombo added pre-existing codebase
mojombo authored
221 assert_equal Time.local(2006, 8, 21, 16), time
222
044fbd7 @mojombo numerizer, time overflow
mojombo authored
223 time = parse_now("sat 4:00", :ambiguous_time_range => :none)
da3a121 @mojombo added pre-existing codebase
mojombo authored
224 assert_equal Time.local(2006, 8, 19, 4), time
225
044fbd7 @mojombo numerizer, time overflow
mojombo authored
226 time = parse_now("sunday 4:20", :ambiguous_time_range => :none)
da3a121 @mojombo added pre-existing codebase
mojombo authored
227 assert_equal Time.local(2006, 8, 20, 4, 20), time
228
044fbd7 @mojombo numerizer, time overflow
mojombo authored
229 time = parse_now("4 pm")
da3a121 @mojombo added pre-existing codebase
mojombo authored
230 assert_equal Time.local(2006, 8, 16, 16), time
231
044fbd7 @mojombo numerizer, time overflow
mojombo authored
232 time = parse_now("4 am", :ambiguous_time_range => :none)
da3a121 @mojombo added pre-existing codebase
mojombo authored
233 assert_equal Time.local(2006, 8, 16, 4), time
234
c7d9591 @mojombo fix 12am/12pm
mojombo authored
235 time = parse_now("12 pm")
236 assert_equal Time.local(2006, 8, 16, 12), time
237
238 time = parse_now("12:01 pm")
239 assert_equal Time.local(2006, 8, 16, 12, 1), time
240
241 time = parse_now("12:01 am")
242 assert_equal Time.local(2006, 8, 16, 0, 1), time
243
244 time = parse_now("12 am")
245 assert_equal Time.local(2006, 8, 16), time
246
044fbd7 @mojombo numerizer, time overflow
mojombo authored
247 time = parse_now("4:00 in the morning")
da3a121 @mojombo added pre-existing codebase
mojombo authored
248 assert_equal Time.local(2006, 8, 16, 4), time
249
044fbd7 @mojombo numerizer, time overflow
mojombo authored
250 time = parse_now("november 4")
7f3625b @mojombo bug fixes, seconds for all dates, hoe
mojombo authored
251 assert_equal Time.local(2006, 11, 4, 12), time
252
044fbd7 @mojombo numerizer, time overflow
mojombo authored
253 time = parse_now("aug 24")
7f3625b @mojombo bug fixes, seconds for all dates, hoe
mojombo authored
254 assert_equal Time.local(2006, 8, 24, 12), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
255 end
256
257 def test_parse_guess_rrr
044fbd7 @mojombo numerizer, time overflow
mojombo authored
258 time = parse_now("friday 1 pm")
da3a121 @mojombo added pre-existing codebase
mojombo authored
259 assert_equal Time.local(2006, 8, 18, 13), time
260
044fbd7 @mojombo numerizer, time overflow
mojombo authored
261 time = parse_now("friday 11 at night")
da3a121 @mojombo added pre-existing codebase
mojombo authored
262 assert_equal Time.local(2006, 8, 18, 23), time
263
044fbd7 @mojombo numerizer, time overflow
mojombo authored
264 time = parse_now("friday 11 in the evening")
da3a121 @mojombo added pre-existing codebase
mojombo authored
265 assert_equal Time.local(2006, 8, 18, 23), time
266
044fbd7 @mojombo numerizer, time overflow
mojombo authored
267 time = parse_now("sunday 6am")
da3a121 @mojombo added pre-existing codebase
mojombo authored
268 assert_equal Time.local(2006, 8, 20, 6), time
f4fef51 @mojombo svrc updates
mojombo authored
269
270 time = parse_now("friday evening at 7")
271 assert_equal Time.local(2006, 8, 18, 19), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
272 end
273
274 def test_parse_guess_gr
8102242 @mojombo reorganized repeaters
mojombo authored
275 # year
276
044fbd7 @mojombo numerizer, time overflow
mojombo authored
277 time = parse_now("this year")
8102242 @mojombo reorganized repeaters
mojombo authored
278 assert_equal Time.local(2006, 10, 24, 12, 30), time
279
044fbd7 @mojombo numerizer, time overflow
mojombo authored
280 time = parse_now("this year", :context => :past)
8102242 @mojombo reorganized repeaters
mojombo authored
281 assert_equal Time.local(2006, 4, 24, 12, 30), time
282
283 # month
284
044fbd7 @mojombo numerizer, time overflow
mojombo authored
285 time = parse_now("this month")
8102242 @mojombo reorganized repeaters
mojombo authored
286 assert_equal Time.local(2006, 8, 24, 12), time
287
044fbd7 @mojombo numerizer, time overflow
mojombo authored
288 time = parse_now("this month", :context => :past)
8102242 @mojombo reorganized repeaters
mojombo authored
289 assert_equal Time.local(2006, 8, 8, 12), time
290
044fbd7 @mojombo numerizer, time overflow
mojombo authored
291 time = Chronic.parse("next month", :now => Time.local(2006, 11, 15))
292 assert_equal Time.local(2006, 12, 16, 12), time
293
8102242 @mojombo reorganized repeaters
mojombo authored
294 # month name
295
044fbd7 @mojombo numerizer, time overflow
mojombo authored
296 time = parse_now("last november")
8102242 @mojombo reorganized repeaters
mojombo authored
297 assert_equal Time.local(2005, 11, 16), time
298
299 # fortnight
300
044fbd7 @mojombo numerizer, time overflow
mojombo authored
301 time = parse_now("this fortnight")
8102242 @mojombo reorganized repeaters
mojombo authored
302 assert_equal Time.local(2006, 8, 21, 19, 30), time
303
044fbd7 @mojombo numerizer, time overflow
mojombo authored
304 time = parse_now("this fortnight", :context => :past)
8102242 @mojombo reorganized repeaters
mojombo authored
305 assert_equal Time.local(2006, 8, 14, 19), time
306
307 # week
308
044fbd7 @mojombo numerizer, time overflow
mojombo authored
309 time = parse_now("this week")
da3a121 @mojombo added pre-existing codebase
mojombo authored
310 assert_equal Time.local(2006, 8, 18, 7, 30), time
311
044fbd7 @mojombo numerizer, time overflow
mojombo authored
312 time = parse_now("this week", :context => :past)
da3a121 @mojombo added pre-existing codebase
mojombo authored
313 assert_equal Time.local(2006, 8, 14, 19), time
314
fc50735 @mojombo weekend support
mojombo authored
315 # weekend
316
044fbd7 @mojombo numerizer, time overflow
mojombo authored
317 time = parse_now("this weekend")
fc50735 @mojombo weekend support
mojombo authored
318 assert_equal Time.local(2006, 8, 20), time
319
044fbd7 @mojombo numerizer, time overflow
mojombo authored
320 time = parse_now("this weekend", :context => :past)
fc50735 @mojombo weekend support
mojombo authored
321 assert_equal Time.local(2006, 8, 13), time
322
044fbd7 @mojombo numerizer, time overflow
mojombo authored
323 time = parse_now("last weekend")
fc50735 @mojombo weekend support
mojombo authored
324 assert_equal Time.local(2006, 8, 13), time
325
8102242 @mojombo reorganized repeaters
mojombo authored
326 # day
327
044fbd7 @mojombo numerizer, time overflow
mojombo authored
328 time = parse_now("this day")
8102242 @mojombo reorganized repeaters
mojombo authored
329 assert_equal Time.local(2006, 8, 16, 19, 30), time
330
044fbd7 @mojombo numerizer, time overflow
mojombo authored
331 time = parse_now("this day", :context => :past)
8102242 @mojombo reorganized repeaters
mojombo authored
332 assert_equal Time.local(2006, 8, 16, 7), time
333
044fbd7 @mojombo numerizer, time overflow
mojombo authored
334 time = parse_now("today")
8102242 @mojombo reorganized repeaters
mojombo authored
335 assert_equal Time.local(2006, 8, 16, 19, 30), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
336
044fbd7 @mojombo numerizer, time overflow
mojombo authored
337 time = parse_now("yesterday")
da3a121 @mojombo added pre-existing codebase
mojombo authored
338 assert_equal Time.local(2006, 8, 15, 12), time
339
044fbd7 @mojombo numerizer, time overflow
mojombo authored
340 time = parse_now("tomorrow")
da3a121 @mojombo added pre-existing codebase
mojombo authored
341 assert_equal Time.local(2006, 8, 17, 12), time
342
8102242 @mojombo reorganized repeaters
mojombo authored
343 # day name
344
044fbd7 @mojombo numerizer, time overflow
mojombo authored
345 time = parse_now("this tuesday")
da3a121 @mojombo added pre-existing codebase
mojombo authored
346 assert_equal Time.local(2006, 8, 22, 12), time
347
044fbd7 @mojombo numerizer, time overflow
mojombo authored
348 time = parse_now("next tuesday")
da3a121 @mojombo added pre-existing codebase
mojombo authored
349 assert_equal Time.local(2006, 8, 22, 12), time
350
044fbd7 @mojombo numerizer, time overflow
mojombo authored
351 time = parse_now("last tuesday")
da3a121 @mojombo added pre-existing codebase
mojombo authored
352 assert_equal Time.local(2006, 8, 15, 12), time
353
044fbd7 @mojombo numerizer, time overflow
mojombo authored
354 time = parse_now("this wed")
da3a121 @mojombo added pre-existing codebase
mojombo authored
355 assert_equal Time.local(2006, 8, 23, 12), time
356
044fbd7 @mojombo numerizer, time overflow
mojombo authored
357 time = parse_now("next wed")
da3a121 @mojombo added pre-existing codebase
mojombo authored
358 assert_equal Time.local(2006, 8, 23, 12), time
359
044fbd7 @mojombo numerizer, time overflow
mojombo authored
360 time = parse_now("last wed")
da3a121 @mojombo added pre-existing codebase
mojombo authored
361 assert_equal Time.local(2006, 8, 9, 12), time
362
8102242 @mojombo reorganized repeaters
mojombo authored
363 # day portion
364
044fbd7 @mojombo numerizer, time overflow
mojombo authored
365 time = parse_now("this morning")
da3a121 @mojombo added pre-existing codebase
mojombo authored
366 assert_equal Time.local(2006, 8, 16, 9), time
367
044fbd7 @mojombo numerizer, time overflow
mojombo authored
368 time = parse_now("tonight")
da3a121 @mojombo added pre-existing codebase
mojombo authored
369 assert_equal Time.local(2006, 8, 16, 22), time
370
f4fef51 @mojombo svrc updates
mojombo authored
371 # minute
372
373 time = parse_now("next minute")
374 assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
375
8102242 @mojombo reorganized repeaters
mojombo authored
376 # second
da3a121 @mojombo added pre-existing codebase
mojombo authored
377
044fbd7 @mojombo numerizer, time overflow
mojombo authored
378 time = parse_now("this second")
da3a121 @mojombo added pre-existing codebase
mojombo authored
379 assert_equal Time.local(2006, 8, 16, 14), time
380
044fbd7 @mojombo numerizer, time overflow
mojombo authored
381 time = parse_now("this second", :context => :past)
8102242 @mojombo reorganized repeaters
mojombo authored
382 assert_equal Time.local(2006, 8, 16, 14), time
383
044fbd7 @mojombo numerizer, time overflow
mojombo authored
384 time = parse_now("next second")
8102242 @mojombo reorganized repeaters
mojombo authored
385 assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
386
044fbd7 @mojombo numerizer, time overflow
mojombo authored
387 time = parse_now("last second")
8102242 @mojombo reorganized repeaters
mojombo authored
388 assert_equal Time.local(2006, 8, 16, 13, 59, 59), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
389 end
390
89360d9 @mojombo bug fixes
mojombo authored
391 def test_parse_guess_grr
044fbd7 @mojombo numerizer, time overflow
mojombo authored
392 time = parse_now("yesterday at 4:00")
da3a121 @mojombo added pre-existing codebase
mojombo authored
393 assert_equal Time.local(2006, 8, 15, 16), time
394
044fbd7 @mojombo numerizer, time overflow
mojombo authored
395 time = parse_now("today at 9:00")
89360d9 @mojombo bug fixes
mojombo authored
396 assert_equal Time.local(2006, 8, 16, 9), time
397
044fbd7 @mojombo numerizer, time overflow
mojombo authored
398 time = parse_now("today at 2100")
89360d9 @mojombo bug fixes
mojombo authored
399 assert_equal Time.local(2006, 8, 16, 21), time
400
044fbd7 @mojombo numerizer, time overflow
mojombo authored
401 time = parse_now("this day at 0900")
89360d9 @mojombo bug fixes
mojombo authored
402 assert_equal Time.local(2006, 8, 16, 9), time
403
044fbd7 @mojombo numerizer, time overflow
mojombo authored
404 time = parse_now("tomorrow at 0900")
89360d9 @mojombo bug fixes
mojombo authored
405 assert_equal Time.local(2006, 8, 17, 9), time
406
044fbd7 @mojombo numerizer, time overflow
mojombo authored
407 time = parse_now("yesterday at 4:00", :ambiguous_time_range => :none)
da3a121 @mojombo added pre-existing codebase
mojombo authored
408 assert_equal Time.local(2006, 8, 15, 4), time
409
044fbd7 @mojombo numerizer, time overflow
mojombo authored
410 time = parse_now("last friday at 4:00")
da3a121 @mojombo added pre-existing codebase
mojombo authored
411 assert_equal Time.local(2006, 8, 11, 16), time
412
044fbd7 @mojombo numerizer, time overflow
mojombo authored
413 time = parse_now("next wed 4:00")
da3a121 @mojombo added pre-existing codebase
mojombo authored
414 assert_equal Time.local(2006, 8, 23, 16), time
415
044fbd7 @mojombo numerizer, time overflow
mojombo authored
416 time = parse_now("yesterday afternoon")
da3a121 @mojombo added pre-existing codebase
mojombo authored
417 assert_equal Time.local(2006, 8, 15, 15), time
418
044fbd7 @mojombo numerizer, time overflow
mojombo authored
419 time = parse_now("last week tuesday")
da3a121 @mojombo added pre-existing codebase
mojombo authored
420 assert_equal Time.local(2006, 8, 8, 12), time
f4fef51 @mojombo svrc updates
mojombo authored
421
422 time = parse_now("tonight at 7")
423 assert_equal Time.local(2006, 8, 16, 19), time
424
425 time = parse_now("tonight 7")
426 assert_equal Time.local(2006, 8, 16, 19), time
427
428 time = parse_now("7 tonight")
429 assert_equal Time.local(2006, 8, 16, 19), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
430 end
f4fef51 @mojombo svrc updates
mojombo authored
431
da3a121 @mojombo added pre-existing codebase
mojombo authored
432 def test_parse_guess_grrr
044fbd7 @mojombo numerizer, time overflow
mojombo authored
433 time = parse_now("today at 6:00pm")
de6b038 @mojombo removed date dependency, improved regex for word variations
mojombo authored
434 assert_equal Time.local(2006, 8, 16, 18), time
435
044fbd7 @mojombo numerizer, time overflow
mojombo authored
436 time = parse_now("today at 6:00am")
89360d9 @mojombo bug fixes
mojombo authored
437 assert_equal Time.local(2006, 8, 16, 6), time
438
044fbd7 @mojombo numerizer, time overflow
mojombo authored
439 time = parse_now("this day 1800")
de6b038 @mojombo removed date dependency, improved regex for word variations
mojombo authored
440 assert_equal Time.local(2006, 8, 16, 18), time
441
044fbd7 @mojombo numerizer, time overflow
mojombo authored
442 time = parse_now("yesterday at 4:00pm")
da3a121 @mojombo added pre-existing codebase
mojombo authored
443 assert_equal Time.local(2006, 8, 15, 16), time
f4fef51 @mojombo svrc updates
mojombo authored
444
445 time = parse_now("tomorrow evening at 7")
446 assert_equal Time.local(2006, 8, 17, 19), time
447
448 time = parse_now("tomorrow morning at 5:30")
449 assert_equal Time.local(2006, 8, 17, 5, 30), time
79527a3 @mojombo fix numerizer bugs
mojombo authored
450
451 time = parse_now("next monday at 12:01 am")
452 assert_equal Time.local(2006, 8, 21, 00, 1), time
453
454 time = parse_now("next monday at 12:01 pm")
455 assert_equal Time.local(2006, 8, 21, 12, 1), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
456 end
457
458 def test_parse_guess_rgr
044fbd7 @mojombo numerizer, time overflow
mojombo authored
459 time = parse_now("afternoon yesterday")
da3a121 @mojombo added pre-existing codebase
mojombo authored
460 assert_equal Time.local(2006, 8, 15, 15), time
461
044fbd7 @mojombo numerizer, time overflow
mojombo authored
462 time = parse_now("tuesday last week")
da3a121 @mojombo added pre-existing codebase
mojombo authored
463 assert_equal Time.local(2006, 8, 8, 12), time
464 end
465
466 def test_parse_guess_s_r_p
467 # past
468
044fbd7 @mojombo numerizer, time overflow
mojombo authored
469 time = parse_now("3 years ago")
470 assert_equal Time.local(2003, 8, 16, 14), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
471
044fbd7 @mojombo numerizer, time overflow
mojombo authored
472 time = parse_now("1 month ago")
473 assert_equal Time.local(2006, 7, 16, 14), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
474
044fbd7 @mojombo numerizer, time overflow
mojombo authored
475 time = parse_now("1 fortnight ago")
476 assert_equal Time.local(2006, 8, 2, 14), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
477
044fbd7 @mojombo numerizer, time overflow
mojombo authored
478 time = parse_now("2 fortnights ago")
479 assert_equal Time.local(2006, 7, 19, 14), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
480
044fbd7 @mojombo numerizer, time overflow
mojombo authored
481 time = parse_now("3 weeks ago")
482 assert_equal Time.local(2006, 7, 26, 14), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
483
044fbd7 @mojombo numerizer, time overflow
mojombo authored
484 time = parse_now("2 weekends ago")
fc50735 @mojombo weekend support
mojombo authored
485 assert_equal Time.local(2006, 8, 5), time
486
044fbd7 @mojombo numerizer, time overflow
mojombo authored
487 time = parse_now("3 days ago")
89360d9 @mojombo bug fixes
mojombo authored
488 assert_equal Time.local(2006, 8, 13, 14), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
489
044fbd7 @mojombo numerizer, time overflow
mojombo authored
490 #time = parse_now("1 monday ago")
da3a121 @mojombo added pre-existing codebase
mojombo authored
491 #assert_equal Time.local(2006, 8, 14, 12), time
492
044fbd7 @mojombo numerizer, time overflow
mojombo authored
493 time = parse_now("5 mornings ago")
da3a121 @mojombo added pre-existing codebase
mojombo authored
494 assert_equal Time.local(2006, 8, 12, 9), time
495
044fbd7 @mojombo numerizer, time overflow
mojombo authored
496 time = parse_now("7 hours ago")
89360d9 @mojombo bug fixes
mojombo authored
497 assert_equal Time.local(2006, 8, 16, 7), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
498
044fbd7 @mojombo numerizer, time overflow
mojombo authored
499 time = parse_now("3 minutes ago")
da3a121 @mojombo added pre-existing codebase
mojombo authored
500 assert_equal Time.local(2006, 8, 16, 13, 57), time
501
044fbd7 @mojombo numerizer, time overflow
mojombo authored
502 time = parse_now("20 seconds before now")
da3a121 @mojombo added pre-existing codebase
mojombo authored
503 assert_equal Time.local(2006, 8, 16, 13, 59, 40), time
504
505 # future
506
044fbd7 @mojombo numerizer, time overflow
mojombo authored
507 time = parse_now("3 years from now")
7f3625b @mojombo bug fixes, seconds for all dates, hoe
mojombo authored
508 assert_equal Time.local(2009, 8, 16, 14, 0, 0), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
509
044fbd7 @mojombo numerizer, time overflow
mojombo authored
510 time = parse_now("6 months hence")
511 assert_equal Time.local(2007, 2, 16, 14), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
512
044fbd7 @mojombo numerizer, time overflow
mojombo authored
513 time = parse_now("3 fortnights hence")
514 assert_equal Time.local(2006, 9, 27, 14), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
515
044fbd7 @mojombo numerizer, time overflow
mojombo authored
516 time = parse_now("1 week from now")
7f3625b @mojombo bug fixes, seconds for all dates, hoe
mojombo authored
517 assert_equal Time.local(2006, 8, 23, 14, 0, 0), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
518
044fbd7 @mojombo numerizer, time overflow
mojombo authored
519 time = parse_now("1 weekend from now")
fc50735 @mojombo weekend support
mojombo authored
520 assert_equal Time.local(2006, 8, 19), time
521
044fbd7 @mojombo numerizer, time overflow
mojombo authored
522 time = parse_now("2 weekends from now")
fc50735 @mojombo weekend support
mojombo authored
523 assert_equal Time.local(2006, 8, 26), time
524
044fbd7 @mojombo numerizer, time overflow
mojombo authored
525 time = parse_now("1 day hence")
89360d9 @mojombo bug fixes
mojombo authored
526 assert_equal Time.local(2006, 8, 17, 14), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
527
044fbd7 @mojombo numerizer, time overflow
mojombo authored
528 time = parse_now("5 mornings hence")
da3a121 @mojombo added pre-existing codebase
mojombo authored
529 assert_equal Time.local(2006, 8, 21, 9), time
530
044fbd7 @mojombo numerizer, time overflow
mojombo authored
531 time = parse_now("1 hour from now")
89360d9 @mojombo bug fixes
mojombo authored
532 assert_equal Time.local(2006, 8, 16, 15), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
533
044fbd7 @mojombo numerizer, time overflow
mojombo authored
534 time = parse_now("20 minutes hence")
da3a121 @mojombo added pre-existing codebase
mojombo authored
535 assert_equal Time.local(2006, 8, 16, 14, 20), time
536
044fbd7 @mojombo numerizer, time overflow
mojombo authored
537 time = parse_now("20 seconds from now")
da3a121 @mojombo added pre-existing codebase
mojombo authored
538 assert_equal Time.local(2006, 8, 16, 14, 0, 20), time
044fbd7 @mojombo numerizer, time overflow
mojombo authored
539
540 time = Chronic.parse("2 months ago", :now => Time.parse("2007-03-07 23:30"))
541 assert_equal Time.local(2007, 1, 7, 23, 30), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
542 end
543
544 def test_parse_guess_p_s_r
044fbd7 @mojombo numerizer, time overflow
mojombo authored
545 time = parse_now("in 3 hours")
89360d9 @mojombo bug fixes
mojombo authored
546 assert_equal Time.local(2006, 8, 16, 17), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
547 end
548
549 def test_parse_guess_s_r_p_a
550 # past
551
044fbd7 @mojombo numerizer, time overflow
mojombo authored
552 time = parse_now("3 years ago tomorrow")
da3a121 @mojombo added pre-existing codebase
mojombo authored
553 assert_equal Time.local(2003, 8, 17, 12), time
554
044fbd7 @mojombo numerizer, time overflow
mojombo authored
555 time = parse_now("3 years ago this friday")
da3a121 @mojombo added pre-existing codebase
mojombo authored
556 assert_equal Time.local(2003, 8, 18, 12), time
557
044fbd7 @mojombo numerizer, time overflow
mojombo authored
558 time = parse_now("3 months ago saturday at 5:00 pm")
da3a121 @mojombo added pre-existing codebase
mojombo authored
559 assert_equal Time.local(2006, 5, 19, 17), time
560
044fbd7 @mojombo numerizer, time overflow
mojombo authored
561 time = parse_now("2 days from this second")
da3a121 @mojombo added pre-existing codebase
mojombo authored
562 assert_equal Time.local(2006, 8, 18, 14), time
563
044fbd7 @mojombo numerizer, time overflow
mojombo authored
564 time = parse_now("7 hours before tomorrow at midnight")
da3a121 @mojombo added pre-existing codebase
mojombo authored
565 assert_equal Time.local(2006, 8, 17, 17), time
566
567 # future
568 end
569
570 def test_parse_guess_o_r_s_r
044fbd7 @mojombo numerizer, time overflow
mojombo authored
571 time = parse_now("3rd wednesday in november")
da3a121 @mojombo added pre-existing codebase
mojombo authored
572 assert_equal Time.local(2006, 11, 15, 12), time
573
044fbd7 @mojombo numerizer, time overflow
mojombo authored
574 time = parse_now("10th wednesday in november")
da3a121 @mojombo added pre-existing codebase
mojombo authored
575 assert_equal nil, time
f4fef51 @mojombo svrc updates
mojombo authored
576
577 # time = parse_now("3rd wednesday in 2007")
578 # assert_equal Time.local(2007, 1, 20, 12), time
da3a121 @mojombo added pre-existing codebase
mojombo authored
579 end
580
581 def test_parse_guess_o_r_g_r
044fbd7 @mojombo numerizer, time overflow
mojombo authored
582 time = parse_now("3rd month next year")
da3a121 @mojombo added pre-existing codebase
mojombo authored
583 assert_equal Time.local(2007, 3, 16, 12, 30), time
584
044fbd7 @mojombo numerizer, time overflow
mojombo authored
585 time = parse_now("3rd thursday this september")
da3a121 @mojombo added pre-existing codebase
mojombo authored
586 assert_equal Time.local(2006, 9, 21, 12), time
587
044fbd7 @mojombo numerizer, time overflow
mojombo authored
588 time = parse_now("4th day last week")
da3a121 @mojombo added pre-existing codebase
mojombo authored
589 assert_equal Time.local(2006, 8, 9, 12), time
590 end
591
592 def test_parse_guess_nonsense
044fbd7 @mojombo numerizer, time overflow
mojombo authored
593 time = parse_now("some stupid nonsense")
da3a121 @mojombo added pre-existing codebase
mojombo authored
594 assert_equal nil, time
79527a3 @mojombo fix numerizer bugs
mojombo authored
595
596 time = parse_now("Ham Sandwich")
597 assert_equal nil, time
da3a121 @mojombo added pre-existing codebase
mojombo authored
598 end
599
600 def test_parse_span
044fbd7 @mojombo numerizer, time overflow
mojombo authored
601 span = parse_now("friday", :guess => false)
da3a121 @mojombo added pre-existing codebase
mojombo authored
602 assert_equal Time.local(2006, 8, 18), span.begin
603 assert_equal Time.local(2006, 8, 19), span.end
604
044fbd7 @mojombo numerizer, time overflow
mojombo authored
605 span = parse_now("november", :guess => false)
da3a121 @mojombo added pre-existing codebase
mojombo authored
606 assert_equal Time.local(2006, 11), span.begin
607 assert_equal Time.local(2006, 12), span.end
fc50735 @mojombo weekend support
mojombo authored
608
609 span = Chronic.parse("weekend" , :now => @time_2006_08_16_14_00_00, :guess => false)
610 assert_equal Time.local(2006, 8, 19), span.begin
611 assert_equal Time.local(2006, 8, 21), span.end
da3a121 @mojombo added pre-existing codebase
mojombo authored
612 end
613
bd654b2 @mojombo add endianness option (Mark Johnson/Thomas Lee)
mojombo authored
614 def test_parse_with_endian_precedence
615 date = '11/02/2007'
616
617 expect_for_middle_endian = Time.local(2007, 11, 2, 12)
618 expect_for_little_endian = Time.local(2007, 2, 11, 12)
619
620 # default precedence should be toward middle endianness
621 assert_equal expect_for_middle_endian, Chronic.parse(date)
622
623 assert_equal expect_for_middle_endian, Chronic.parse(date, :endian_precedence => [:middle, :little])
624
625 assert_equal expect_for_little_endian, Chronic.parse(date, :endian_precedence => [:little, :middle])
626 end
627
044fbd7 @mojombo numerizer, time overflow
mojombo authored
628 def test_parse_words
629 assert_equal parse_now("33 days from now"), parse_now("thirty-three days from now")
630 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")
631 assert_equal parse_now("may 10th"), parse_now("may tenth")
632 end
633
634 def test_parse_only_complete_pointers
635 assert_equal parse_now("eat pasty buns today at 2pm"), @time_2006_08_16_14_00_00
636 assert_equal parse_now("futuristically speaking today at 2pm"), @time_2006_08_16_14_00_00
637 assert_equal parse_now("meeting today at 2pm"), @time_2006_08_16_14_00_00
638 end
639
79527a3 @mojombo fix numerizer bugs
mojombo authored
640 def test_am_pm
641 assert_equal Time.local(2006, 8, 16), parse_now("8/16/2006 at 12am")
642 assert_equal Time.local(2006, 8, 16, 12), parse_now("8/16/2006 at 12pm")
643 end
644
1acb559 parse 'a' or 'p' as 'am' and 'pm' google-calendar style
Lee Bankewitz authored
645 def test_a_p
646 assert_equal Time.local(2006, 8, 16, 0, 15), parse_now("8/16/2006 at 12:15a")
647 assert_equal Time.local(2006, 8, 16, 18, 30), parse_now("8/16/2006 at 6:30p")
648 end
649
da3a121 @mojombo added pre-existing codebase
mojombo authored
650 def test_argument_validation
651 assert_raise(Chronic::InvalidArgumentException) do
652 time = Chronic.parse("may 27", :foo => :bar)
653 end
654
655 assert_raise(Chronic::InvalidArgumentException) do
656 time = Chronic.parse("may 27", :context => :bar)
657 end
658 end
659
3d7d840 @mojombo seasons and weekday/weekend support (Edwin Chen)
mojombo authored
660 def test_seasons
661 t = parse_now("this spring", :guess => false)
662 assert_equal Time.local(2007, 3, 20), t.begin
663 assert_equal Time.local(2007, 6, 20), t.end
664
665 t = parse_now("this winter", :guess => false)
666 assert_equal Time.local(2006, 12, 22, 23), t.begin
667 assert_equal Time.local(2007, 3, 19), t.end
668
669 t = parse_now("last spring", :guess => false)
670 assert_equal Time.local(2006, 3, 20, 23), t.begin
671 assert_equal Time.local(2006, 6, 20), t.end
672
673 t = parse_now("last winter", :guess => false)
674 assert_equal Time.local(2005, 12, 22, 23), t.begin
675 assert_equal Time.local(2006, 3, 19, 23), t.end
676
677 t = parse_now("next spring", :guess => false)
678 assert_equal Time.local(2007, 3, 20), t.begin
679 assert_equal Time.local(2007, 6, 20), t.end
680 end
681
79527a3 @mojombo fix numerizer bugs
mojombo authored
682 # regression
683
684 # def test_partial
685 # assert_equal '', parse_now("2 hours")
686 # end
687
688 def test_days_in_november
689 t1 = Chronic.parse('1st thursday in november', :now => Time.local(2007))
690 assert_equal Time.local(2007, 11, 1, 12), t1
691
692 t1 = Chronic.parse('1st friday in november', :now => Time.local(2007))
693 assert_equal Time.local(2007, 11, 2, 12), t1
694
695 t1 = Chronic.parse('1st saturday in november', :now => Time.local(2007))
696 assert_equal Time.local(2007, 11, 3, 12), t1
697
698 t1 = Chronic.parse('1st sunday in november', :now => Time.local(2007))
699 assert_equal Time.local(2007, 11, 4, 11), t1
700
701 # Chronic.debug = true
702 #
703 # t1 = Chronic.parse('1st monday in november', :now => Time.local(2007))
704 # assert_equal Time.local(2007, 11, 5, 11), t1
705 end
706
044fbd7 @mojombo numerizer, time overflow
mojombo authored
707 private
708 def parse_now(string, options={})
709 Chronic.parse(string, {:now => TIME_2006_08_16_14_00_00 }.merge(options))
710 end
bd654b2 @mojombo add endianness option (Mark Johnson/Thomas Lee)
mojombo authored
711 end
Something went wrong with that request. Please try again.