chronic-davispuh 0.10.2.v0.1da32066b3f46f2506b3471e39557497e34afa27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/Gemfile +3 -0
- data/HISTORY.md +243 -0
- data/LICENSE +21 -0
- data/README.md +185 -0
- data/Rakefile +68 -0
- data/chronic.gemspec +27 -0
- data/lib/chronic.rb +122 -0
- data/lib/chronic/arrow.rb +270 -0
- data/lib/chronic/date.rb +272 -0
- data/lib/chronic/definition.rb +208 -0
- data/lib/chronic/dictionary.rb +36 -0
- data/lib/chronic/handler.rb +44 -0
- data/lib/chronic/handlers/anchor.rb +65 -0
- data/lib/chronic/handlers/arrow.rb +84 -0
- data/lib/chronic/handlers/date.rb +270 -0
- data/lib/chronic/handlers/date_time.rb +72 -0
- data/lib/chronic/handlers/general.rb +130 -0
- data/lib/chronic/handlers/narrow.rb +54 -0
- data/lib/chronic/handlers/time.rb +167 -0
- data/lib/chronic/handlers/time_zone.rb +50 -0
- data/lib/chronic/objects/anchor_object.rb +263 -0
- data/lib/chronic/objects/arrow_object.rb +27 -0
- data/lib/chronic/objects/date_object.rb +164 -0
- data/lib/chronic/objects/date_time_object.rb +64 -0
- data/lib/chronic/objects/handler_object.rb +81 -0
- data/lib/chronic/objects/narrow_object.rb +85 -0
- data/lib/chronic/objects/time_object.rb +96 -0
- data/lib/chronic/objects/time_zone_object.rb +27 -0
- data/lib/chronic/parser.rb +154 -0
- data/lib/chronic/span.rb +32 -0
- data/lib/chronic/tag.rb +84 -0
- data/lib/chronic/tags/day_name.rb +34 -0
- data/lib/chronic/tags/day_portion.rb +33 -0
- data/lib/chronic/tags/day_special.rb +30 -0
- data/lib/chronic/tags/grabber.rb +29 -0
- data/lib/chronic/tags/keyword.rb +63 -0
- data/lib/chronic/tags/month_name.rb +39 -0
- data/lib/chronic/tags/ordinal.rb +52 -0
- data/lib/chronic/tags/pointer.rb +28 -0
- data/lib/chronic/tags/rational.rb +35 -0
- data/lib/chronic/tags/scalar.rb +101 -0
- data/lib/chronic/tags/season_name.rb +31 -0
- data/lib/chronic/tags/separator.rb +130 -0
- data/lib/chronic/tags/sign.rb +35 -0
- data/lib/chronic/tags/time_special.rb +34 -0
- data/lib/chronic/tags/time_zone.rb +56 -0
- data/lib/chronic/tags/unit.rb +174 -0
- data/lib/chronic/time.rb +141 -0
- data/lib/chronic/time_zone.rb +80 -0
- data/lib/chronic/token.rb +61 -0
- data/lib/chronic/token_group.rb +271 -0
- data/lib/chronic/tokenizer.rb +42 -0
- data/lib/chronic/version.rb +3 -0
- data/test/helper.rb +12 -0
- data/test/test_chronic.rb +190 -0
- data/test/test_daylight_savings.rb +98 -0
- data/test/test_handler.rb +113 -0
- data/test/test_parsing.rb +1520 -0
- data/test/test_span.rb +23 -0
- data/test/test_token.rb +31 -0
- metadata +218 -0
@@ -0,0 +1,1520 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestParsing < 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_generic
|
12
|
+
time = Chronic.parse("2012-08-02T13:00:00")
|
13
|
+
assert_equal Time.local(2012, 8, 2, 13), time
|
14
|
+
|
15
|
+
time = Chronic.parse("2012-08-02T13:00:00+01:00")
|
16
|
+
assert_equal Time.utc(2012, 8, 2, 12), time
|
17
|
+
|
18
|
+
time = Chronic.parse("2012-08-02T08:00:00-04:00")
|
19
|
+
assert_equal Time.utc(2012, 8, 2, 12), time
|
20
|
+
|
21
|
+
time = Chronic.parse("2013-08-01T19:30:00.345-07:00")
|
22
|
+
time2 = Time.parse("2013-08-01 019:30:00.345-07:00")
|
23
|
+
assert_in_delta time, time2, 0.001
|
24
|
+
|
25
|
+
time = Chronic.parse("2013-08-01T19:30:00.34-07:00")
|
26
|
+
time2 = Time.parse("2013-08-01T19:30:00.34-07:00")
|
27
|
+
assert_in_delta time, time2, 0.001
|
28
|
+
|
29
|
+
time = Chronic.parse("2013-08-01T19:30:00.3456789-07:00")
|
30
|
+
time2 = Time.parse("2013-08-01T19:30:00.3456789-07:00")
|
31
|
+
assert_in_delta time, time2, 0.001
|
32
|
+
|
33
|
+
time = Chronic.parse("2012-08-02T12:00:00Z")
|
34
|
+
assert_equal Time.utc(2012, 8, 2, 12), time
|
35
|
+
|
36
|
+
time = Chronic.parse("2012-01-03 01:00:00.100")
|
37
|
+
time2 = Time.parse("2012-01-03 01:00:00.100")
|
38
|
+
assert_in_delta time, time2, 0.001
|
39
|
+
|
40
|
+
time = Chronic.parse("2012-01-03 01:00:00.234567")
|
41
|
+
time2 = Time.parse("2012-01-03 01:00:00.234567")
|
42
|
+
assert_in_delta time, time2, 0.000001
|
43
|
+
|
44
|
+
assert_nil Chronic.parse("1/1/32.1")
|
45
|
+
|
46
|
+
time = Chronic.parse("28th", {:guess => :begin})
|
47
|
+
assert_equal Time.new(Time.now.year, Time.now.month, 28), time
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_handle_rmn_sd
|
51
|
+
time = parse_now("aug 3")
|
52
|
+
assert_equal Time.local(2007, 8, 3, 12), time
|
53
|
+
|
54
|
+
time = parse_now("aug 3", :context => :past)
|
55
|
+
assert_equal Time.local(2006, 8, 3, 12), time
|
56
|
+
|
57
|
+
time = parse_now("aug. 3")
|
58
|
+
assert_equal Time.local(2007, 8, 3, 12), time
|
59
|
+
|
60
|
+
time = parse_now("aug 20")
|
61
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
62
|
+
|
63
|
+
time = parse_now("aug-20")
|
64
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
65
|
+
|
66
|
+
time = parse_now("aug 20", :context => :future)
|
67
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
68
|
+
|
69
|
+
time = parse_now("may 27")
|
70
|
+
assert_equal Time.local(2007, 5, 27, 12), time
|
71
|
+
|
72
|
+
time = parse_now("may 28", :context => :past)
|
73
|
+
assert_equal Time.local(2006, 5, 28, 12), time
|
74
|
+
|
75
|
+
time = parse_now("may 28 5pm", :context => :past)
|
76
|
+
assert_equal Time.local(2006, 5, 28, 17, 30), time
|
77
|
+
|
78
|
+
time = parse_now("may 28 at 5pm", :context => :past)
|
79
|
+
assert_equal Time.local(2006, 5, 28, 17, 30), time
|
80
|
+
|
81
|
+
time = parse_now("may 28 at 5:32.19pm", :context => :past)
|
82
|
+
assert_equal Time.local(2006, 5, 28, 17, 32, 19), time
|
83
|
+
|
84
|
+
time = parse_now("may 28 at 5:32:19.764")
|
85
|
+
assert_in_delta Time.local(2007, 5, 28, 17, 32, 19, 764000), time, 0.001
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_handle_rmn_sd_on
|
89
|
+
time = parse_now("5pm on may 28")
|
90
|
+
assert_equal Time.local(2007, 5, 28, 17, 30), time
|
91
|
+
|
92
|
+
time = parse_now("5pm may 28")
|
93
|
+
assert_equal Time.local(2007, 5, 28, 17, 30), time
|
94
|
+
|
95
|
+
time = parse_now("5 on may 28", :ambiguous_time_range => :none)
|
96
|
+
assert_equal Time.local(2007, 5, 28, 05, 30), time
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_handle_rmn_od
|
100
|
+
time = parse_now("may 27th")
|
101
|
+
assert_equal Time.local(2007, 5, 27, 12), time
|
102
|
+
|
103
|
+
time = parse_now("may 27th", :context => :past)
|
104
|
+
assert_equal Time.local(2006, 5, 27, 12), time
|
105
|
+
|
106
|
+
time = parse_now("may 27th 5:00 pm", :context => :past)
|
107
|
+
assert_equal Time.local(2006, 5, 27, 17, 0, 30), time
|
108
|
+
|
109
|
+
time = parse_now("may 27th at 5pm", :context => :past)
|
110
|
+
assert_equal Time.local(2006, 5, 27, 17, 30), time
|
111
|
+
|
112
|
+
time = parse_now("may 27th at 5", :ambiguous_time_range => :none)
|
113
|
+
assert_equal Time.local(2007, 5, 27, 5, 30), time
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_handle_od_rm
|
117
|
+
time = parse_now("fifteenth of this month")
|
118
|
+
assert_equal Time.local(2007, 8, 15, 12), time
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_handle_od_rmn
|
122
|
+
time = parse_now("22nd February")
|
123
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
124
|
+
|
125
|
+
time = parse_now("31st of may at 6:30pm")
|
126
|
+
assert_equal Time.local(2007, 5, 31, 18, 30, 30), time
|
127
|
+
|
128
|
+
time = parse_now("11th december 8am")
|
129
|
+
assert_equal Time.local(2006, 12, 11, 8, 30), time
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_handle_sy_rmn_od
|
133
|
+
time = parse_now("2009 May 22nd")
|
134
|
+
assert_equal Time.local(2009, 05, 22, 12), time
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_handle_sd_rmn
|
138
|
+
time = parse_now("22 February")
|
139
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
140
|
+
|
141
|
+
time = parse_now("22 feb")
|
142
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
143
|
+
|
144
|
+
time = parse_now("22-feb")
|
145
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
146
|
+
|
147
|
+
time = parse_now("31 of may at 6:30pm")
|
148
|
+
assert_equal Time.local(2007, 5, 31, 18, 30, 30), time
|
149
|
+
|
150
|
+
time = parse_now("11 december 8am")
|
151
|
+
assert_equal Time.local(2006, 12, 11, 8, 30), time
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_handle_rmn_od_on
|
155
|
+
time = parse_now("5:00 pm may 27th", :context => :past)
|
156
|
+
assert_equal Time.local(2006, 5, 27, 17, 0, 30), time
|
157
|
+
|
158
|
+
time = parse_now("05:00 pm may 27th", :context => :past)
|
159
|
+
assert_equal Time.local(2006, 5, 27, 17, 0, 30), time
|
160
|
+
|
161
|
+
time = parse_now("5pm on may 27th", :context => :past)
|
162
|
+
assert_equal Time.local(2006, 5, 27, 17, 30), time
|
163
|
+
|
164
|
+
time = parse_now("5 on may 27th", :ambiguous_time_range => :none)
|
165
|
+
assert_equal Time.local(2007, 5, 27, 5, 30), time
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_handle_rmn_sy
|
169
|
+
time = parse_now("may 97")
|
170
|
+
assert_equal Time.local(1997, 5, 16, 12), time
|
171
|
+
|
172
|
+
time = parse_now("may 33", :ambiguous_year_future_bias => 10)
|
173
|
+
assert_equal Time.local(2033, 5, 16, 12), time
|
174
|
+
|
175
|
+
time = parse_now("may 32")
|
176
|
+
assert_equal Time.local(2032, 5, 16, 12, 0, 0), time
|
177
|
+
|
178
|
+
time = parse_now("may '01")
|
179
|
+
assert_equal Time.local(2001, 5, 16, 12, 0, 0), time
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_handle_rdn_rmn_sd_t_tz_sy
|
183
|
+
time = parse_now("Mon Apr 02 17:00:00 PDT 2007")
|
184
|
+
assert_equal 1175558400, time.to_i
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_handle_sy_sm_sd_t_tz
|
188
|
+
time = parse_now("2011-07-03 22:11:35 +0100")
|
189
|
+
assert_equal 1309727495, time.to_i
|
190
|
+
|
191
|
+
time = parse_now("2011-07-03 22:11:35 +01:00")
|
192
|
+
assert_equal 1309727495, time.to_i
|
193
|
+
|
194
|
+
time = parse_now("2011-07-03 16:11:35 -05:00")
|
195
|
+
assert_equal 1309727495, time.to_i
|
196
|
+
|
197
|
+
time = parse_now("2011-07-03 21:11:35 UTC")
|
198
|
+
assert_equal 1309727495, time.to_i
|
199
|
+
|
200
|
+
time = parse_now("2011-07-03 21:11:35.362 UTC")
|
201
|
+
assert_in_delta 1309727495.362, time.to_f, 0.001
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_handle_rmn_sd_sy
|
205
|
+
time = parse_now("November 18, 2010")
|
206
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
207
|
+
|
208
|
+
time = parse_now("Jan 1,2010")
|
209
|
+
assert_equal Time.local(2010, 1, 1, 12), time
|
210
|
+
|
211
|
+
time = parse_now("February 14, 2004")
|
212
|
+
assert_equal Time.local(2004, 2, 14, 12), time
|
213
|
+
|
214
|
+
time = parse_now("jan 3 2010")
|
215
|
+
assert_equal Time.local(2010, 1, 3, 12), time
|
216
|
+
|
217
|
+
time = parse_now("jan 3 2010 midnight")
|
218
|
+
assert_equal Time.local(2010, 1, 4, 0), time
|
219
|
+
|
220
|
+
time = parse_now("jan 3 2010 at midnight")
|
221
|
+
assert_equal Time.local(2010, 1, 4, 0), time
|
222
|
+
|
223
|
+
time = parse_now("jan 3 2010 at 4", :ambiguous_time_range => :none)
|
224
|
+
assert_equal Time.local(2010, 1, 3, 4, 30), time
|
225
|
+
|
226
|
+
time = parse_now("may 27, 1979")
|
227
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
228
|
+
|
229
|
+
time = parse_now("may 27 79")
|
230
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
231
|
+
|
232
|
+
time = parse_now("may 27 79 4:30")
|
233
|
+
assert_equal Time.local(1979, 5, 27, 16, 30, 30), time
|
234
|
+
|
235
|
+
time = parse_now("may 27 79 at 4:30", :ambiguous_time_range => :none)
|
236
|
+
assert_equal Time.local(1979, 5, 27, 4, 30, 30), time
|
237
|
+
|
238
|
+
time = parse_now("may 27 32")
|
239
|
+
assert_equal Time.local(2032, 5, 27, 12, 0, 0), time
|
240
|
+
|
241
|
+
time = parse_now("oct 5 2012 1045pm")
|
242
|
+
assert_equal Time.local(2012, 10, 5, 22, 45, 30), time
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_handle_rmn_od_sy
|
246
|
+
time = parse_now("may 1st 01")
|
247
|
+
assert_equal Time.local(2001, 5, 1, 12), time
|
248
|
+
|
249
|
+
time = parse_now("November 18th 2010")
|
250
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
251
|
+
|
252
|
+
time = parse_now("November 18th, 2010")
|
253
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
254
|
+
|
255
|
+
time = parse_now("November 18th 2010 midnight")
|
256
|
+
assert_equal Time.local(2010, 11, 19, 0), time
|
257
|
+
|
258
|
+
time = parse_now("November 18th 2010 at midnight")
|
259
|
+
assert_equal Time.local(2010, 11, 19, 0), time
|
260
|
+
|
261
|
+
time = parse_now("November 18th 2010 at 4")
|
262
|
+
assert_equal Time.local(2010, 11, 18, 16, 30), time
|
263
|
+
|
264
|
+
time = parse_now("November 18th 2010 at 4", :ambiguous_time_range => :none)
|
265
|
+
assert_equal Time.local(2010, 11, 18, 4, 30), time
|
266
|
+
|
267
|
+
time = parse_now("March 30th, 1979")
|
268
|
+
assert_equal Time.local(1979, 3, 30, 12), time
|
269
|
+
|
270
|
+
time = parse_now("March 30th 79")
|
271
|
+
assert_equal Time.local(1979, 3, 30, 12), time
|
272
|
+
|
273
|
+
time = parse_now("March 30th 79 4:30")
|
274
|
+
assert_equal Time.local(1979, 3, 30, 16, 30, 30), time
|
275
|
+
|
276
|
+
time = parse_now("March 30th 79 at 4:30", :ambiguous_time_range => :none)
|
277
|
+
assert_equal Time.local(1979, 3, 30, 4, 30, 30), time
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_handle_od_rmn_sy
|
281
|
+
time = parse_now("22nd February 2012")
|
282
|
+
assert_equal Time.local(2012, 2, 22, 12), time
|
283
|
+
|
284
|
+
time = parse_now("11th december 79")
|
285
|
+
assert_equal Time.local(1979, 12, 11, 12), time
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_handle_sd_rmn_sy
|
289
|
+
time = parse_now("3 jan 2010")
|
290
|
+
assert_equal Time.local(2010, 1, 3, 12), time
|
291
|
+
|
292
|
+
time = parse_now("3 jan 2010 4pm")
|
293
|
+
assert_equal Time.local(2010, 1, 3, 16, 30), time
|
294
|
+
|
295
|
+
time = parse_now("27 Oct 2006 7:30pm")
|
296
|
+
assert_equal Time.local(2006, 10, 27, 19, 30, 30), time
|
297
|
+
|
298
|
+
time = parse_now("3 jan 10")
|
299
|
+
assert_equal Time.local(2010, 1, 3, 12), time
|
300
|
+
|
301
|
+
time = parse_now("3 jan 10", :endian_precedence => :little)
|
302
|
+
assert_equal Time.local(2010, 1, 3, 12), time
|
303
|
+
|
304
|
+
time = parse_now("3 jan 10", :endian_precedence => :middle)
|
305
|
+
assert_equal Time.local(2010, 1, 3, 12), time
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_handle_sm_sd_sy
|
309
|
+
time = parse_now("5/27/1979")
|
310
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
311
|
+
|
312
|
+
time = parse_now("5/27/1979 4am")
|
313
|
+
assert_equal Time.local(1979, 5, 27, 4, 30), time
|
314
|
+
|
315
|
+
time = parse_now("7/12/11")
|
316
|
+
assert_equal Time.local(2011, 7, 12, 12), time
|
317
|
+
|
318
|
+
time = parse_now("7/12/11", :endian_precedence => :little)
|
319
|
+
assert_equal Time.local(2011, 12, 7, 12), time
|
320
|
+
|
321
|
+
time = parse_now("9/19/2011 6:05:57 PM")
|
322
|
+
assert_equal Time.local(2011, 9, 19, 18, 05, 57), time
|
323
|
+
|
324
|
+
# month day overflows
|
325
|
+
time = parse_now("30/2/2000")
|
326
|
+
assert_nil time
|
327
|
+
|
328
|
+
time = parse_now("2013-03-12 17:00", :context => :past, :guess => :begin)
|
329
|
+
assert_equal Time.local(2013, 3, 12, 17, 0, 0), time
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_handle_sd_sm_sy
|
333
|
+
time = parse_now("27/5/1979")
|
334
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
335
|
+
|
336
|
+
time = parse_now("27/5/1979 @ 0700")
|
337
|
+
assert_equal Time.local(1979, 5, 27, 7, 0, 30), time
|
338
|
+
|
339
|
+
time = parse_now("03/18/2012 09:26 pm")
|
340
|
+
assert_equal Time.local(2012, 3, 18, 21, 26, 30), time
|
341
|
+
|
342
|
+
time = parse_now("30.07.2013 16:34:22")
|
343
|
+
assert_equal Time.local(2013, 7, 30, 16, 34, 22), time
|
344
|
+
|
345
|
+
time = parse_now("09.08.2013")
|
346
|
+
assert_equal Time.local(2013, 8, 9, 12), time
|
347
|
+
|
348
|
+
time = parse_now("30-07-2013 21:53:49")
|
349
|
+
assert_equal Time.local(2013, 7, 30, 21, 53, 49), time
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_handle_sy_sm_sd
|
353
|
+
time = parse_now("2000-1-1")
|
354
|
+
assert_equal Time.local(2000, 1, 1, 12), time
|
355
|
+
|
356
|
+
time = parse_now("2006-08-20")
|
357
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
358
|
+
|
359
|
+
time = parse_now("2006-08-20 7pm")
|
360
|
+
assert_equal Time.local(2006, 8, 20, 19, 30), time
|
361
|
+
|
362
|
+
time = parse_now("2006-08-20 03:00")
|
363
|
+
assert_equal Time.local(2006, 8, 20, 3, 0, 30), time
|
364
|
+
|
365
|
+
time = parse_now("2006-08-20 03:30:30")
|
366
|
+
assert_equal Time.local(2006, 8, 20, 3, 30, 30), time
|
367
|
+
|
368
|
+
time = parse_now("2006-08-20 15:30:30")
|
369
|
+
assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
|
370
|
+
|
371
|
+
time = parse_now("2006-08-20 15:30.30")
|
372
|
+
assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
|
373
|
+
|
374
|
+
time = parse_now("2006-08-20 15:30:30:000536")
|
375
|
+
assert_in_delta Time.local(2006, 8, 20, 15, 30, 30, 536), time, 0.000001
|
376
|
+
|
377
|
+
time = parse_now("1902-08-20")
|
378
|
+
assert_equal Time.local(1902, 8, 20, 12, 0, 0), time
|
379
|
+
|
380
|
+
time = parse_now("2013.07.30 11:45:23", :ambiguous_time_range => :none)
|
381
|
+
assert_equal Time.local(2013, 7, 30, 11, 45, 23), time
|
382
|
+
|
383
|
+
time = parse_now("2013.08.09")
|
384
|
+
assert_equal Time.local(2013, 8, 9, 12, 0, 0), time
|
385
|
+
|
386
|
+
# exif date time original
|
387
|
+
time = parse_now("2012:05:25 22:06:50")
|
388
|
+
assert_equal Time.local(2012, 5, 25, 22, 6, 50), time
|
389
|
+
end
|
390
|
+
|
391
|
+
def test_handle_sm_sd
|
392
|
+
time = parse_now("05/06")
|
393
|
+
assert_equal Time.local(2007, 5, 6, 12), time
|
394
|
+
|
395
|
+
time = parse_now("05/06", :endian_precedence => [:little, :middle])
|
396
|
+
assert_equal Time.local(2007, 6, 5, 12), time
|
397
|
+
|
398
|
+
time = parse_now("05/06 6:05:57 PM")
|
399
|
+
assert_equal Time.local(2007, 5, 6, 18, 05, 57), time
|
400
|
+
|
401
|
+
time = parse_now("05/06 6:05:57 PM", :endian_precedence => [:little, :middle])
|
402
|
+
assert_equal Time.local(2007, 6, 5, 18, 05, 57), time
|
403
|
+
|
404
|
+
time = parse_now("13/09")
|
405
|
+
assert_equal Time.local(2006, 9, 13, 12), time
|
406
|
+
|
407
|
+
# future
|
408
|
+
time = parse_now("05/06") # future is default context
|
409
|
+
assert_equal Time.local(2007, 5, 6, 12), time
|
410
|
+
|
411
|
+
time = parse_now("1/13", :context => :future)
|
412
|
+
assert_equal Time.local(2007, 1, 13, 12), time
|
413
|
+
|
414
|
+
time = parse_now("3/13", :context => :none)
|
415
|
+
assert_equal Time.local(2006, 3, 13, 12), time
|
416
|
+
|
417
|
+
time = parse_now("12/1", :context => :past)
|
418
|
+
assert_equal Time.local(2005, 12, 1, 12), time
|
419
|
+
|
420
|
+
time = parse_now("12/1", :context => :future)
|
421
|
+
assert_equal Time.local(2006, 12, 1, 12), time
|
422
|
+
|
423
|
+
time = parse_now("12/1", :context => :none)
|
424
|
+
assert_equal Time.local(2006, 12, 1, 12), time
|
425
|
+
|
426
|
+
time = parse_now("8/1", :context => :past)
|
427
|
+
assert_equal Time.local(2006, 8, 1, 12), time
|
428
|
+
|
429
|
+
time = parse_now("8/1", :context => :future)
|
430
|
+
assert_equal Time.local(2007, 8, 1, 12), time
|
431
|
+
|
432
|
+
time = parse_now("8/1", :context => :none)
|
433
|
+
assert_equal Time.local(2006, 8, 1, 12), time
|
434
|
+
|
435
|
+
time = parse_now("1/1", :context => :past)
|
436
|
+
assert_equal Time.local(2006, 1, 1, 12), time
|
437
|
+
|
438
|
+
time = parse_now("1/1", :context => :future)
|
439
|
+
assert_equal Time.local(2007, 1, 1, 12), time
|
440
|
+
|
441
|
+
time = parse_now("1/1", :context => :none)
|
442
|
+
assert_equal Time.local(2006, 1, 1, 12), time
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_handle_sm_sy
|
446
|
+
time = parse_now("05/06", :endian_precedence => :month_year)
|
447
|
+
assert_equal Time.local(2006, 5, 16, 12), time
|
448
|
+
|
449
|
+
time = parse_now("12/06", :endian_precedence => :month_year)
|
450
|
+
assert_equal Time.local(2006, 12, 16, 12), time
|
451
|
+
|
452
|
+
time = parse_now("13/06", :endian_precedence => :month_year)
|
453
|
+
assert_nil time
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_handle_sy_sm
|
457
|
+
time = parse_now("2012-06")
|
458
|
+
assert_equal Time.local(2012, 06, 16), time
|
459
|
+
|
460
|
+
time = parse_now("2013/12")
|
461
|
+
assert_equal Time.local(2013, 12, 16, 12, 0), time
|
462
|
+
end
|
463
|
+
|
464
|
+
def test_handle_r
|
465
|
+
time = parse_now("9am on Saturday")
|
466
|
+
assert_equal Time.local(2006, 8, 19, 9, 30), time
|
467
|
+
|
468
|
+
time = parse_now("on Tuesday")
|
469
|
+
assert_equal Time.local(2006, 8, 22, 12), time
|
470
|
+
|
471
|
+
time = parse_now("1:00:00 PM", :context => :none)
|
472
|
+
assert_equal Time.local(2006, 8, 16, 13), time
|
473
|
+
|
474
|
+
time = parse_now("01:00:00 PM")
|
475
|
+
assert_equal Time.local(2006, 8, 17, 13), time
|
476
|
+
|
477
|
+
time = parse_now("today at 02:00:00", :hours24 => false)
|
478
|
+
assert_equal Time.local(2006, 8, 16, 14), time
|
479
|
+
|
480
|
+
time = parse_now("today at 02:00:00 AM", :hours24 => false)
|
481
|
+
assert_equal Time.local(2006, 8, 16, 2), time
|
482
|
+
|
483
|
+
time = parse_now("today at 3:00:00", :hours24 => true)
|
484
|
+
assert_equal Time.local(2006, 8, 16, 3), time
|
485
|
+
|
486
|
+
time = parse_now("today at 03:00:00", :hours24 => true)
|
487
|
+
assert_equal Time.local(2006, 8, 16, 3), time
|
488
|
+
|
489
|
+
time = parse_now("tomorrow at 4a.m.", :guess => :begin)
|
490
|
+
assert_equal Time.local(2006, 8, 17, 4), time
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_handle_r_g_r
|
494
|
+
end
|
495
|
+
|
496
|
+
def test_handle_srp
|
497
|
+
end
|
498
|
+
|
499
|
+
def test_handle_s_r_p
|
500
|
+
end
|
501
|
+
|
502
|
+
def test_handle_p_s_r
|
503
|
+
end
|
504
|
+
|
505
|
+
def test_handle_s_r_p_a
|
506
|
+
time1 = parse_now("two days ago 0:0:0am")
|
507
|
+
time2 = parse_now("two days ago 00:00:00am")
|
508
|
+
assert_equal time1, time2
|
509
|
+
end
|
510
|
+
|
511
|
+
def test_handle_orr
|
512
|
+
time = parse_now("5th tuesday in january")
|
513
|
+
assert_equal Time.local(2007, 01, 30, 12), time
|
514
|
+
|
515
|
+
time = parse_now("5th tuesday in february")
|
516
|
+
assert_nil time
|
517
|
+
|
518
|
+
%W(jan feb march april may june july aug sep oct nov dec).each_with_index do |month, index|
|
519
|
+
time = parse_now("5th tuesday in #{month}")
|
520
|
+
|
521
|
+
if time then
|
522
|
+
assert_equal time.month, index+1
|
523
|
+
end
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
def test_handle_o_r_s_r
|
528
|
+
time = parse_now("3rd wednesday in november")
|
529
|
+
assert_equal Time.local(2006, 11, 15, 12), time
|
530
|
+
|
531
|
+
time = parse_now("10th wednesday in november")
|
532
|
+
assert_nil time
|
533
|
+
|
534
|
+
time = parse_now("3rd saturday in 2007")
|
535
|
+
assert_equal Time.local(2007, 1, 20, 12), time
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_handle_o_r_g_r
|
539
|
+
time = parse_now("3rd month next year", :guess => false)
|
540
|
+
assert_equal Time.local(2007, 3), time.begin
|
541
|
+
|
542
|
+
time = parse_now("3rd month next year", :guess => false)
|
543
|
+
assert_equal Time.local(2007, 3, 1), time.begin
|
544
|
+
|
545
|
+
time = parse_now("3rd thursday this september")
|
546
|
+
assert_equal Time.local(2006, 9, 21, 12), time
|
547
|
+
|
548
|
+
now = Time.parse("1/10/2010")
|
549
|
+
time = parse_now("3rd thursday this november", :now => now)
|
550
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
551
|
+
|
552
|
+
time = parse_now("4th day last week")
|
553
|
+
assert_equal Time.local(2006, 8, 9, 12), time
|
554
|
+
end
|
555
|
+
|
556
|
+
def test_handle_sm_rmn_sy
|
557
|
+
time = parse_now('30-Mar-11')
|
558
|
+
assert_equal Time.local(2011, 3, 30, 12), time
|
559
|
+
|
560
|
+
time = parse_now('31-Aug-12')
|
561
|
+
assert_equal Time.local(2012, 8, 31, 12), time
|
562
|
+
end
|
563
|
+
|
564
|
+
# end of testing handlers
|
565
|
+
|
566
|
+
def test_parse_guess_r
|
567
|
+
time = parse_now("friday")
|
568
|
+
assert_equal Time.local(2006, 8, 18, 12), time
|
569
|
+
|
570
|
+
time = parse_now("tue")
|
571
|
+
assert_equal Time.local(2006, 8, 22, 12), time
|
572
|
+
|
573
|
+
time = parse_now("5")
|
574
|
+
assert_equal Time.local(2006, 8, 16, 17, 30), time
|
575
|
+
|
576
|
+
time = Chronic.parse("5", :now => Time.local(2006, 8, 16, 3, 0, 0, 0), :ambiguous_time_range => :none, :guess => :begin)
|
577
|
+
assert_equal Time.local(2006, 8, 16, 5), time
|
578
|
+
|
579
|
+
time = parse_now("13:00")
|
580
|
+
assert_equal Time.local(2006, 8, 17, 13, 0, 30), time
|
581
|
+
|
582
|
+
time = parse_now("13:45")
|
583
|
+
assert_equal Time.local(2006, 8, 17, 13, 45, 30), time
|
584
|
+
|
585
|
+
time = parse_now("1:01pm", :context => :past)
|
586
|
+
assert_equal Time.local(2006, 8, 16, 13, 01, 30), time
|
587
|
+
|
588
|
+
time = parse_now("2:01pm", :context => :none)
|
589
|
+
assert_equal Time.local(2006, 8, 16, 14, 01, 30), time
|
590
|
+
|
591
|
+
time = parse_now("november")
|
592
|
+
assert_equal Time.local(2006, 11, 16), time
|
593
|
+
end
|
594
|
+
|
595
|
+
def test_parse_guess_rr
|
596
|
+
time = parse_now("friday 13:00", :guess => :begin)
|
597
|
+
assert_equal Time.local(2006, 8, 18, 13), time
|
598
|
+
|
599
|
+
time = parse_now("monday 4:00")
|
600
|
+
assert_equal Time.local(2006, 8, 21, 16, 0, 30), time
|
601
|
+
|
602
|
+
time = parse_now("sat 4:00", :ambiguous_time_range => :none, :guess => :begin)
|
603
|
+
assert_equal Time.local(2006, 8, 19, 4), time
|
604
|
+
|
605
|
+
time = parse_now("sunday 4:20", :ambiguous_time_range => :none)
|
606
|
+
assert_equal Time.local(2006, 8, 20, 4, 20, 30), time
|
607
|
+
|
608
|
+
time = parse_now("4 pm")
|
609
|
+
assert_equal Time.local(2006, 8, 16, 16, 30), time
|
610
|
+
|
611
|
+
time = parse_now("4 am", :ambiguous_time_range => :none)
|
612
|
+
assert_equal Time.local(2006, 8, 17, 4, 30), time
|
613
|
+
|
614
|
+
time = parse_now("12 pm")
|
615
|
+
assert_equal Time.local(2006, 8, 17, 12, 30), time
|
616
|
+
|
617
|
+
time = parse_now("12:01 pm")
|
618
|
+
assert_equal Time.local(2006, 8, 17, 12, 1, 30), time
|
619
|
+
|
620
|
+
time = parse_now("12:01 am")
|
621
|
+
assert_equal Time.local(2006, 8, 17, 0, 1, 30), time
|
622
|
+
|
623
|
+
time = parse_now("12 am")
|
624
|
+
assert_equal Time.local(2006, 8, 17, 0, 30), time
|
625
|
+
|
626
|
+
time = parse_now("4:00 in the morning")
|
627
|
+
assert_equal Time.local(2006, 8, 17, 4, 0, 30), time
|
628
|
+
|
629
|
+
time = parse_now("0:10")
|
630
|
+
assert_equal Time.local(2006, 8, 17, 0, 10, 30), time
|
631
|
+
|
632
|
+
time = parse_now("november 4")
|
633
|
+
assert_equal Time.local(2006, 11, 4, 12), time
|
634
|
+
|
635
|
+
time = parse_now("aug 24")
|
636
|
+
assert_equal Time.local(2006, 8, 24, 12), time
|
637
|
+
end
|
638
|
+
|
639
|
+
def test_parse_guess_rrr
|
640
|
+
time = parse_now("friday 1 pm")
|
641
|
+
assert_equal Time.local(2006, 8, 18, 13, 30), time
|
642
|
+
|
643
|
+
time = parse_now("friday 11 at night")
|
644
|
+
assert_equal Time.local(2006, 8, 18, 23, 30), time
|
645
|
+
|
646
|
+
time = parse_now("friday 11 in the evening")
|
647
|
+
assert_equal Time.local(2006, 8, 18, 23, 30), time
|
648
|
+
|
649
|
+
time = parse_now("sunday 6am")
|
650
|
+
assert_equal Time.local(2006, 8, 20, 6, 30), time
|
651
|
+
|
652
|
+
time = parse_now("friday evening at 7")
|
653
|
+
assert_equal Time.local(2006, 8, 18, 19, 30), time
|
654
|
+
end
|
655
|
+
|
656
|
+
def test_parse_guess_gr
|
657
|
+
# year
|
658
|
+
|
659
|
+
time = parse_now("this year", :guess => false)
|
660
|
+
assert_equal Time.local(2006, 8, 16).to_date, time.begin.to_date
|
661
|
+
|
662
|
+
time = parse_now("this year", :context => :past, :guess => false)
|
663
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
664
|
+
|
665
|
+
# month
|
666
|
+
|
667
|
+
time = parse_now("this month")
|
668
|
+
assert_equal Time.local(2006, 8, 24, 7), time
|
669
|
+
|
670
|
+
time = parse_now("this month", :context => :past)
|
671
|
+
assert_equal Time.local(2006, 8, 8, 19), time
|
672
|
+
|
673
|
+
time = Chronic.parse("next month", :now => Time.local(2006, 11, 15))
|
674
|
+
assert_equal Time.local(2006, 12, 16, 12), time
|
675
|
+
|
676
|
+
# month name
|
677
|
+
|
678
|
+
time = parse_now("last november")
|
679
|
+
assert_equal Time.local(2005, 11, 16), time
|
680
|
+
|
681
|
+
# fortnight
|
682
|
+
|
683
|
+
time = parse_now("this fortnight")
|
684
|
+
assert_equal Time.local(2006, 8, 21, 19), time
|
685
|
+
|
686
|
+
time = parse_now("this fortnight", :context => :past)
|
687
|
+
assert_equal Time.local(2006, 8, 11, 7), time
|
688
|
+
|
689
|
+
# week
|
690
|
+
|
691
|
+
time = parse_now("this week")
|
692
|
+
assert_equal Time.local(2006, 8, 18, 7, 0), time
|
693
|
+
|
694
|
+
time = parse_now("this week", :context => :past)
|
695
|
+
assert_equal Time.local(2006, 8, 14, 19), time
|
696
|
+
|
697
|
+
time = parse_now("this week", :context => :past, :guess => :begin)
|
698
|
+
assert_equal Time.local(2006, 8, 13), time
|
699
|
+
|
700
|
+
time = parse_now("this week", :context => :past, :guess => :begin, :week_start => :monday)
|
701
|
+
assert_equal Time.local(2006, 8, 14), time
|
702
|
+
|
703
|
+
# weekend
|
704
|
+
|
705
|
+
time = parse_now("this weekend")
|
706
|
+
assert_equal Time.local(2006, 8, 20), time
|
707
|
+
|
708
|
+
time = parse_now("this weekend", :context => :past)
|
709
|
+
assert_equal Time.local(2006, 8, 13), time
|
710
|
+
|
711
|
+
time = parse_now("last weekend")
|
712
|
+
assert_equal Time.local(2006, 8, 13), time
|
713
|
+
|
714
|
+
# day
|
715
|
+
|
716
|
+
time = parse_now("this day")
|
717
|
+
assert_equal Time.local(2006, 8, 16, 19), time
|
718
|
+
|
719
|
+
time = parse_now("this day", :context => :past)
|
720
|
+
assert_equal Time.local(2006, 8, 16, 7), time
|
721
|
+
|
722
|
+
time = parse_now("today")
|
723
|
+
assert_equal Time.local(2006, 8, 16, 19), time
|
724
|
+
|
725
|
+
time = parse_now("yesterday")
|
726
|
+
assert_equal Time.local(2006, 8, 15, 12), time
|
727
|
+
|
728
|
+
now = Time.parse("2011-05-27 23:10") # after 11pm
|
729
|
+
time = parse_now("yesterday", :now => now)
|
730
|
+
assert_equal Time.local(2011, 05, 26, 12), time
|
731
|
+
|
732
|
+
time = parse_now("tomorrow")
|
733
|
+
assert_equal Time.local(2006, 8, 17, 12), time
|
734
|
+
|
735
|
+
# day name
|
736
|
+
|
737
|
+
time = parse_now("this tuesday")
|
738
|
+
assert_equal Time.local(2006, 8, 22, 12), time
|
739
|
+
|
740
|
+
time = parse_now("next tuesday")
|
741
|
+
assert_equal Time.local(2006, 8, 22, 12), time
|
742
|
+
|
743
|
+
time = parse_now("last tuesday")
|
744
|
+
assert_equal Time.local(2006, 8, 15, 12), time
|
745
|
+
|
746
|
+
time = parse_now("this wed")
|
747
|
+
assert_equal Time.local(2006, 8, 23, 12), time
|
748
|
+
|
749
|
+
time = parse_now("next wed")
|
750
|
+
assert_equal Time.local(2006, 8, 23, 12), time
|
751
|
+
|
752
|
+
time = parse_now("last wed")
|
753
|
+
assert_equal Time.local(2006, 8, 9, 12), time
|
754
|
+
|
755
|
+
monday = Time.local(2006, 8, 21, 12)
|
756
|
+
assert_equal monday, parse_now("mon")
|
757
|
+
assert_equal monday, parse_now("mun")
|
758
|
+
|
759
|
+
tuesday = Time.local(2006, 8, 22, 12)
|
760
|
+
assert_equal tuesday, parse_now("tue")
|
761
|
+
assert_equal tuesday, parse_now("tus")
|
762
|
+
|
763
|
+
wednesday = Time.local(2006, 8, 23, 12)
|
764
|
+
assert_equal wednesday, parse_now("wed")
|
765
|
+
assert_equal wednesday, parse_now("wenns")
|
766
|
+
|
767
|
+
thursday = Time.local(2006, 8, 17, 12)
|
768
|
+
assert_equal thursday, parse_now("thu")
|
769
|
+
assert_equal thursday, parse_now("thur")
|
770
|
+
|
771
|
+
friday = Time.local(2006, 8, 18, 12)
|
772
|
+
assert_equal friday, parse_now("fri")
|
773
|
+
assert_equal friday, parse_now("fry")
|
774
|
+
|
775
|
+
saturday = Time.local(2006, 8, 19, 12)
|
776
|
+
assert_equal saturday, parse_now("sat")
|
777
|
+
assert_equal saturday, parse_now("satterday")
|
778
|
+
|
779
|
+
sunday = Time.local(2006, 8, 20, 12)
|
780
|
+
assert_equal sunday, parse_now("sun")
|
781
|
+
assert_equal sunday, parse_now("sum")
|
782
|
+
|
783
|
+
# day portion
|
784
|
+
|
785
|
+
time = parse_now("this morning")
|
786
|
+
assert_equal Time.local(2006, 8, 16, 9), time
|
787
|
+
|
788
|
+
time = parse_now("tonight")
|
789
|
+
assert_equal Time.local(2006, 8, 16, 22), time
|
790
|
+
|
791
|
+
# hour
|
792
|
+
|
793
|
+
time = parse_now("next hr")
|
794
|
+
assert_equal Time.local(2006, 8, 16, 15, 30, 0), time
|
795
|
+
|
796
|
+
time = parse_now("next hrs")
|
797
|
+
assert_equal Time.local(2006, 8, 16, 15, 30, 0), time
|
798
|
+
|
799
|
+
# minute
|
800
|
+
|
801
|
+
time = parse_now("next min")
|
802
|
+
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
803
|
+
|
804
|
+
time = parse_now("next mins")
|
805
|
+
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
806
|
+
|
807
|
+
time = parse_now("next minute")
|
808
|
+
assert_equal Time.local(2006, 8, 16, 14, 1, 30), time
|
809
|
+
|
810
|
+
# second
|
811
|
+
|
812
|
+
time = parse_now("next sec")
|
813
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
|
814
|
+
|
815
|
+
time = parse_now("next secs")
|
816
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
|
817
|
+
|
818
|
+
time = parse_now("this second")
|
819
|
+
assert_equal Time.local(2006, 8, 16, 14), time
|
820
|
+
|
821
|
+
time = parse_now("this second", :context => :past)
|
822
|
+
assert_equal Time.local(2006, 8, 16, 14), time
|
823
|
+
|
824
|
+
time = parse_now("next second")
|
825
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
|
826
|
+
|
827
|
+
time = parse_now("last second")
|
828
|
+
assert_equal Time.local(2006, 8, 16, 13, 59, 59), time
|
829
|
+
end
|
830
|
+
|
831
|
+
def test_parse_guess_grr
|
832
|
+
time = parse_now("yesterday at 4:00")
|
833
|
+
assert_equal Time.local(2006, 8, 15, 16, 0, 30), time
|
834
|
+
|
835
|
+
time = parse_now("today at 9:00", :hours24 => true)
|
836
|
+
assert_equal Time.local(2006, 8, 16, 9, 0, 30), time
|
837
|
+
|
838
|
+
time = parse_now("today at 2100")
|
839
|
+
assert_equal Time.local(2006, 8, 16, 21, 0, 30), time
|
840
|
+
|
841
|
+
time = parse_now("this day at 0900", :guess => :begin)
|
842
|
+
assert_equal Time.local(2006, 8, 16, 9), time
|
843
|
+
|
844
|
+
time = parse_now("tomorrow at 0900")
|
845
|
+
assert_equal Time.local(2006, 8, 17, 9, 0, 30), time
|
846
|
+
|
847
|
+
time = parse_now("yesterday at 4:00", :ambiguous_time_range => :none)
|
848
|
+
assert_equal Time.local(2006, 8, 15, 4, 0, 30), time
|
849
|
+
|
850
|
+
time = parse_now("last friday at 4:00")
|
851
|
+
assert_equal Time.local(2006, 8, 11, 16, 0, 30), time
|
852
|
+
|
853
|
+
time = parse_now("next wed 4:00")
|
854
|
+
assert_equal Time.local(2006, 8, 23, 16, 0, 30), time
|
855
|
+
|
856
|
+
time = parse_now("yesterday afternoon")
|
857
|
+
assert_equal Time.local(2006, 8, 15, 15), time
|
858
|
+
|
859
|
+
time = parse_now("last week tuesday")
|
860
|
+
assert_equal Time.local(2006, 8, 8, 12), time
|
861
|
+
|
862
|
+
time = parse_now("tonight at 7")
|
863
|
+
assert_equal Time.local(2006, 8, 16, 19, 30), time
|
864
|
+
|
865
|
+
time = parse_now("tonight 7")
|
866
|
+
assert_equal Time.local(2006, 8, 16, 19, 30), time
|
867
|
+
|
868
|
+
time = parse_now("7 tonight")
|
869
|
+
assert_equal Time.local(2006, 8, 16, 19, 30), time
|
870
|
+
end
|
871
|
+
|
872
|
+
def test_parse_guess_grrr
|
873
|
+
time = parse_now("today at 6:00pm")
|
874
|
+
assert_equal Time.local(2006, 8, 16, 18, 0, 30), time
|
875
|
+
|
876
|
+
time = parse_now("today at 6:00am")
|
877
|
+
assert_equal Time.local(2006, 8, 16, 6, 0, 30), time
|
878
|
+
|
879
|
+
time = parse_now("this day 1800")
|
880
|
+
assert_equal Time.local(2006, 8, 16, 18, 0, 30), time
|
881
|
+
|
882
|
+
time = parse_now("yesterday at 4:00pm")
|
883
|
+
assert_equal Time.local(2006, 8, 15, 16, 0, 30), time
|
884
|
+
|
885
|
+
time = parse_now("tomorrow evening at 7")
|
886
|
+
assert_equal Time.local(2006, 8, 17, 19, 30), time
|
887
|
+
|
888
|
+
time = parse_now("tomorrow morning at 5:30")
|
889
|
+
assert_equal Time.local(2006, 8, 17, 5, 30, 30), time
|
890
|
+
|
891
|
+
time = parse_now("next monday at 12:01 am")
|
892
|
+
assert_equal Time.local(2006, 8, 21, 00, 1, 30), time
|
893
|
+
|
894
|
+
time = parse_now("next monday at 12:01 pm")
|
895
|
+
assert_equal Time.local(2006, 8, 21, 12, 1, 30), time
|
896
|
+
|
897
|
+
# with context
|
898
|
+
time = parse_now("sunday at 8:15pm", :context => :past)
|
899
|
+
assert_equal Time.local(2006, 8, 13, 20, 15, 30), time
|
900
|
+
end
|
901
|
+
|
902
|
+
def test_parse_guess_rgr
|
903
|
+
time = parse_now("afternoon yesterday")
|
904
|
+
assert_equal Time.local(2006, 8, 15, 15), time
|
905
|
+
|
906
|
+
time = parse_now("tuesday last week")
|
907
|
+
assert_equal Time.local(2006, 8, 8, 12), time
|
908
|
+
end
|
909
|
+
|
910
|
+
def test_parse_guess_a_ago
|
911
|
+
time = parse_now("AN hour ago", :guess => :begin)
|
912
|
+
assert_equal Time.local(2006, 8, 16, 13), time
|
913
|
+
|
914
|
+
time = parse_now("A day ago", :guess => :begin)
|
915
|
+
assert_equal Time.local(2006, 8, 15, 14), time
|
916
|
+
|
917
|
+
time = parse_now("a month ago", :guess => :begin)
|
918
|
+
assert_equal Time.local(2006, 7, 16, 14), time
|
919
|
+
|
920
|
+
time = parse_now("a year ago", :guess => :begin)
|
921
|
+
assert_equal Time.local(2005, 8, 16, 14), time
|
922
|
+
end
|
923
|
+
|
924
|
+
def test_parse_guess_s_r_p
|
925
|
+
# past
|
926
|
+
|
927
|
+
time = parse_now("3 years ago", :guess => :begin)
|
928
|
+
assert_equal Time.local(2003, 8, 16, 14), time
|
929
|
+
|
930
|
+
time = parse_now("1 month ago", :guess => :begin)
|
931
|
+
assert_equal Time.local(2006, 7, 16, 14), time
|
932
|
+
|
933
|
+
time = parse_now("1 fortnight ago", :guess => :begin)
|
934
|
+
assert_equal Time.local(2006, 8, 2, 14), time
|
935
|
+
|
936
|
+
time = parse_now("2 fortnights ago", :guess => :begin)
|
937
|
+
assert_equal Time.local(2006, 7, 19, 14), time
|
938
|
+
|
939
|
+
time = parse_now("3 weeks ago", :guess => :begin)
|
940
|
+
assert_equal Time.local(2006, 7, 26, 14), time
|
941
|
+
|
942
|
+
time = parse_now("2 weekends ago", :guess => :begin)
|
943
|
+
assert_equal Date.new(2006, 8, 5), time.to_date
|
944
|
+
|
945
|
+
time = parse_now("3 days ago", :guess => :begin)
|
946
|
+
assert_equal Time.local(2006, 8, 13, 14), time
|
947
|
+
|
948
|
+
time = parse_now("1 monday ago", :guess => :begin)
|
949
|
+
assert_equal Time.local(2006, 8, 14, 14), time
|
950
|
+
|
951
|
+
time = parse_now("5 mornings ago")
|
952
|
+
assert_equal Time.local(2006, 8, 12, 9), time
|
953
|
+
|
954
|
+
time = parse_now("7 hours ago", :guess => :begin)
|
955
|
+
assert_equal Time.local(2006, 8, 16, 7), time
|
956
|
+
|
957
|
+
time = parse_now("3 minutes ago", :guess => :begin)
|
958
|
+
assert_equal Time.local(2006, 8, 16, 13, 57), time
|
959
|
+
|
960
|
+
time = parse_now("20 seconds before now", :guess => :begin)
|
961
|
+
assert_equal Time.local(2006, 8, 16, 13, 59, 40), time
|
962
|
+
|
963
|
+
# future
|
964
|
+
|
965
|
+
time = parse_now("3 years from now", :guess => :begin)
|
966
|
+
assert_equal Time.local(2009, 8, 16, 14, 0, 0), time
|
967
|
+
|
968
|
+
time = parse_now("6 months hence", :guess => :begin)
|
969
|
+
assert_equal Time.local(2007, 2, 16, 14), time
|
970
|
+
|
971
|
+
time = parse_now("3 fortnights hence", :guess => :begin)
|
972
|
+
assert_equal Time.local(2006, 9, 27, 14), time
|
973
|
+
|
974
|
+
time = parse_now("1 week from now", :guess => :begin)
|
975
|
+
assert_equal Time.local(2006, 8, 23, 14, 0, 0), time
|
976
|
+
|
977
|
+
time = parse_now("1 weekend from now", :guess => :begin)
|
978
|
+
assert_equal Time.local(2006, 8, 19), time
|
979
|
+
|
980
|
+
time = parse_now("2 weekends from now", :guess => :begin)
|
981
|
+
assert_equal Time.local(2006, 8, 26), time
|
982
|
+
|
983
|
+
time = parse_now("1 day hence", :guess => :begin)
|
984
|
+
assert_equal Time.local(2006, 8, 17, 14), time
|
985
|
+
|
986
|
+
time = parse_now("5 mornings hence")
|
987
|
+
assert_equal Time.local(2006, 8, 21, 9), time
|
988
|
+
|
989
|
+
time = parse_now("1 hour from now", :guess => :begin)
|
990
|
+
assert_equal Time.local(2006, 8, 16, 15), time
|
991
|
+
|
992
|
+
time = parse_now("20 minutes hence", :guess => :begin)
|
993
|
+
assert_equal Time.local(2006, 8, 16, 14, 20), time
|
994
|
+
|
995
|
+
time = parse_now("20 seconds from now", :guess => :begin)
|
996
|
+
assert_equal Time.local(2006, 8, 16, 14, 0, 20), time
|
997
|
+
|
998
|
+
time = Chronic.parse("2 months ago", :now => Time.parse("2007-03-07 23:30"), :guess => :begin)
|
999
|
+
assert_equal Time.local(2007, 1, 7, 23, 30), time
|
1000
|
+
|
1001
|
+
# Two repeaters
|
1002
|
+
time = parse_now("25 minutes and 20 seconds from now")
|
1003
|
+
assert_equal Time.local(2006, 8, 16, 14, 25, 20), time
|
1004
|
+
|
1005
|
+
time = parse_now("24 hours and 20 minutes from now")
|
1006
|
+
assert_equal Time.local(2006, 8, 17, 14, 20, 0), time
|
1007
|
+
|
1008
|
+
time = parse_now("24 hours 20 minutes from now")
|
1009
|
+
assert_equal Time.local(2006, 8, 17, 14, 20, 0), time
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
def test_parse_guess_p_s_r
|
1013
|
+
time = parse_now("in 3 hours", :guess => :end)
|
1014
|
+
assert_equal Time.local(2006, 8, 16, 17), time
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
def test_parse_guess_s_r_p_a
|
1018
|
+
# past
|
1019
|
+
|
1020
|
+
time = parse_now("3 years ago tomorrow")
|
1021
|
+
assert_equal Time.local(2003, 8, 17, 12), time
|
1022
|
+
|
1023
|
+
time = parse_now("3 years ago this friday")
|
1024
|
+
assert_equal Time.local(2003, 8, 22, 12), time
|
1025
|
+
|
1026
|
+
time = parse_now("3 months ago saturday at 5:00 pm")
|
1027
|
+
assert_equal Time.local(2006, 5, 19, 17, 0, 30), time
|
1028
|
+
|
1029
|
+
time = parse_now("2 days from this second")
|
1030
|
+
assert_equal Time.local(2006, 8, 18, 14), time
|
1031
|
+
|
1032
|
+
time = parse_now("7 hours before tomorrow at midnight")
|
1033
|
+
assert_equal Time.local(2006, 8, 17, 17), time
|
1034
|
+
|
1035
|
+
# future
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
def test_parse_guess_rmn_s_r_p
|
1039
|
+
time = parse_now("september 3 years ago", :guess => :start)
|
1040
|
+
assert_equal Time.local(2003, 9), time
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
def test_parse_guess_o_r_g_r
|
1044
|
+
time = parse_now("3rd month next year", :guess => false)
|
1045
|
+
assert_equal Time.local(2007, 3), time.begin
|
1046
|
+
|
1047
|
+
time = parse_now("3rd month next year", :guess => false)
|
1048
|
+
assert_equal Time.local(2007, 3, 1), time.begin
|
1049
|
+
|
1050
|
+
time = parse_now("3rd thursday this september")
|
1051
|
+
assert_equal Time.local(2006, 9, 21, 12), time
|
1052
|
+
|
1053
|
+
now = Time.parse("1/10/2010")
|
1054
|
+
time = parse_now("3rd thursday this november", :now => now)
|
1055
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
1056
|
+
|
1057
|
+
time = parse_now("4th day last week")
|
1058
|
+
assert_equal Time.local(2006, 8, 9, 12), time
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
def test_parse_guess_nonsense
|
1062
|
+
time = parse_now("some stupid nonsense")
|
1063
|
+
assert_nil time
|
1064
|
+
|
1065
|
+
time = parse_now("Ham Sandwich")
|
1066
|
+
assert_nil time
|
1067
|
+
|
1068
|
+
time = parse_now("t")
|
1069
|
+
assert_nil time
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
def test_parse_span
|
1073
|
+
span = parse_now("friday", :guess => false)
|
1074
|
+
assert_equal Time.local(2006, 8, 18), span.begin
|
1075
|
+
assert_equal Time.local(2006, 8, 19), span.end
|
1076
|
+
|
1077
|
+
span = parse_now("november", :guess => false)
|
1078
|
+
assert_equal Time.local(2006, 11), span.begin
|
1079
|
+
assert_equal Time.local(2006, 12), span.end
|
1080
|
+
|
1081
|
+
span = Chronic.parse("weekend" , :now => @time_2006_08_16_14_00_00, :guess => false)
|
1082
|
+
assert_equal Time.local(2006, 8, 19), span.begin
|
1083
|
+
assert_equal Time.local(2006, 8, 21), span.end
|
1084
|
+
end
|
1085
|
+
|
1086
|
+
def test_parse_with_endian_precedence
|
1087
|
+
date = '11/02/2007'
|
1088
|
+
|
1089
|
+
expect_for_middle_endian = Time.local(2007, 11, 2, 12)
|
1090
|
+
expect_for_little_endian = Time.local(2007, 2, 11, 12)
|
1091
|
+
|
1092
|
+
# default precedence should be toward middle endianness
|
1093
|
+
assert_equal expect_for_middle_endian, Chronic.parse(date)
|
1094
|
+
|
1095
|
+
assert_equal expect_for_middle_endian, Chronic.parse(date, :endian_precedence => [:middle, :little])
|
1096
|
+
|
1097
|
+
assert_equal expect_for_little_endian, Chronic.parse(date, :endian_precedence => [:little, :middle])
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
def test_parse_words
|
1101
|
+
assert_equal parse_now("33 days from now"), parse_now("thirty-three days from now")
|
1102
|
+
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")
|
1103
|
+
assert_equal parse_now("may 10th"), parse_now("may tenth")
|
1104
|
+
assert_equal parse_now("second monday in january"), parse_now("2nd monday in january")
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
def test_relative_to_an_hour_before
|
1108
|
+
# example prenormalization "10 to 2" becomes "10 minutes past 2"
|
1109
|
+
assert_equal Time.local(2006, 8, 16, 13, 50, 30), parse_now("10 to 2")
|
1110
|
+
assert_equal Time.local(2006, 8, 16, 13, 50, 30), parse_now("10 till 2")
|
1111
|
+
assert_equal Time.local(2006, 8, 16, 13, 50), parse_now("10 prior to 2", :guess => :begin)
|
1112
|
+
assert_equal Time.local(2006, 8, 16, 13, 50, 30), parse_now("10 before 2")
|
1113
|
+
|
1114
|
+
# uses the current hour, so 2006-08-16 13:50:00, not 14:50
|
1115
|
+
assert_equal Time.local(2006, 8, 16, 13, 50, 30), parse_now("10 to")
|
1116
|
+
assert_equal Time.local(2006, 8, 16, 13, 50), parse_now("10 till", :guess => :begin)
|
1117
|
+
|
1118
|
+
assert_equal Time.local(2006, 8, 16, 15, 45), parse_now("quarter to 4", :guess => :begin)
|
1119
|
+
end
|
1120
|
+
|
1121
|
+
def test_relative_to_an_hour_after
|
1122
|
+
# not nil
|
1123
|
+
assert_equal Time.local(2006, 8, 16, 14, 10), parse_now("10 after 2", :guess => :begin)
|
1124
|
+
assert_equal Time.local(2006, 8, 16, 14, 10), parse_now("10 past 2", :guess => :begin)
|
1125
|
+
assert_equal Time.local(2006, 8, 16, 14, 30), parse_now("half past 2", :guess => :begin)
|
1126
|
+
end
|
1127
|
+
|
1128
|
+
def test_parse_only_complete_pointers
|
1129
|
+
assert_equal parse_now("eat pasty buns today at 2pm", :guess => :begin), @time_2006_08_16_14_00_00
|
1130
|
+
assert_equal parse_now("futuristically speaking today at 2pm", :guess => :begin), @time_2006_08_16_14_00_00
|
1131
|
+
assert_equal parse_now("meeting today at 2pm", :guess => :begin), @time_2006_08_16_14_00_00
|
1132
|
+
end
|
1133
|
+
|
1134
|
+
def test_am_pm
|
1135
|
+
assert_equal Time.local(2006, 8, 16, 0, 30), parse_now("8/16/2006 at 12am")
|
1136
|
+
assert_equal Time.local(2006, 8, 16, 12, 30), parse_now("8/16/2006 at 12pm")
|
1137
|
+
end
|
1138
|
+
|
1139
|
+
def test_a_p
|
1140
|
+
assert_equal Time.local(2006, 8, 16, 0, 15, 30), parse_now("8/16/2006 at 12:15a")
|
1141
|
+
assert_equal Time.local(2006, 8, 16, 18, 30, 30), parse_now("8/16/2006 at 6:30p")
|
1142
|
+
end
|
1143
|
+
|
1144
|
+
def test_seasons
|
1145
|
+
t = parse_now("this spring", :guess => false)
|
1146
|
+
assert_equal Time.local(2007, 3, 20), t.begin
|
1147
|
+
assert_equal Time.local(2007, 6, 21), t.end
|
1148
|
+
|
1149
|
+
t = parse_now("this winter", :guess => false)
|
1150
|
+
assert_equal Time.local(2006, 12, 22), t.begin
|
1151
|
+
assert_equal Time.local(2007, 3, 20), t.end
|
1152
|
+
|
1153
|
+
t = parse_now("last spring", :guess => false)
|
1154
|
+
assert_equal Time.local(2006, 3, 20), t.begin
|
1155
|
+
assert_equal Time.local(2006, 6, 21), t.end
|
1156
|
+
|
1157
|
+
t = parse_now("last winter", :guess => false)
|
1158
|
+
assert_equal Time.local(2005, 12, 22), t.begin
|
1159
|
+
assert_equal Time.local(2006, 3, 20), t.end
|
1160
|
+
|
1161
|
+
t = parse_now("next spring", :guess => false)
|
1162
|
+
assert_equal Time.local(2007, 3, 20), t.begin
|
1163
|
+
assert_equal Time.local(2007, 6, 21), t.end
|
1164
|
+
end
|
1165
|
+
|
1166
|
+
def test_quarters
|
1167
|
+
time = parse_now("this quarter", {:guess => false, :context => :none})
|
1168
|
+
assert_equal Time.local(2006, 7, 1), time.begin
|
1169
|
+
assert_equal Time.local(2006, 10, 1), time.end
|
1170
|
+
|
1171
|
+
time = parse_now("next quarter", {:guess => false, :context => :none})
|
1172
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
1173
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
1174
|
+
|
1175
|
+
time = parse_now("last quarter", {:guess => false, :context => :none})
|
1176
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
1177
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
def test_quarters_srp
|
1181
|
+
time = parse_now("1 quarter ago", :guess => false)
|
1182
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
1183
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
1184
|
+
|
1185
|
+
time = parse_now("2 quarters ago", :guess => false)
|
1186
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
1187
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
1188
|
+
|
1189
|
+
time = parse_now("1 quarter from now", :guess => false)
|
1190
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
1191
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
1192
|
+
end
|
1193
|
+
|
1194
|
+
def test_quarters_named
|
1195
|
+
["Q1", "first quarter", "1st quarter"].each do |string|
|
1196
|
+
time = parse_now(string, :guess => false, :context => :none)
|
1197
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
1198
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
1199
|
+
|
1200
|
+
time = parse_now(string, :guess => false, :context => :future)
|
1201
|
+
assert_equal Time.local(2007, 1, 1), time.begin
|
1202
|
+
assert_equal Time.local(2007, 4, 1), time.end
|
1203
|
+
|
1204
|
+
time = parse_now(string, :guess => false, :context => :past)
|
1205
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
1206
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
1207
|
+
|
1208
|
+
time = parse_now("#{string} 2005", :guess => false)
|
1209
|
+
assert_equal Time.local(2005, 1, 1), time.begin
|
1210
|
+
assert_equal Time.local(2005, 4, 1), time.end
|
1211
|
+
|
1212
|
+
time = parse_now("2005 #{string}", :guess => false)
|
1213
|
+
assert_equal Time.local(2005, 1, 1), time.begin
|
1214
|
+
assert_equal Time.local(2005, 4, 1), time.end
|
1215
|
+
|
1216
|
+
time = parse_now("#{string} this year", :guess => false)
|
1217
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
1218
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
1219
|
+
|
1220
|
+
time = parse_now("this year #{string}", :guess => false)
|
1221
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
1222
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
1223
|
+
|
1224
|
+
time = parse_now("#{string} next year", :guess => false)
|
1225
|
+
assert_equal Time.local(2007, 1, 1), time.begin
|
1226
|
+
assert_equal Time.local(2007, 4, 1), time.end
|
1227
|
+
|
1228
|
+
time = parse_now("next year #{string}", :guess => false)
|
1229
|
+
assert_equal Time.local(2007, 1, 1), time.begin
|
1230
|
+
assert_equal Time.local(2007, 4, 1), time.end
|
1231
|
+
|
1232
|
+
time = parse_now("this #{string}", :guess => false, context: :none)
|
1233
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
1234
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
1235
|
+
|
1236
|
+
time = parse_now("last #{string}", :guess => false, context: :none)
|
1237
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
1238
|
+
assert_equal Time.local(2006, 4, 1), time.end
|
1239
|
+
|
1240
|
+
time = parse_now("next #{string}", :guess => false, context: :none)
|
1241
|
+
assert_equal Time.local(2007, 1, 1), time.begin
|
1242
|
+
assert_equal Time.local(2007, 4, 1), time.end
|
1243
|
+
end
|
1244
|
+
|
1245
|
+
["Q2", "second quarter", "2nd quarter"].each do |string|
|
1246
|
+
time = parse_now(string, :guess => false, :context => :none)
|
1247
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
1248
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
1249
|
+
|
1250
|
+
time = parse_now(string, :guess => false, :context => :future)
|
1251
|
+
assert_equal Time.local(2007, 4, 1), time.begin
|
1252
|
+
assert_equal Time.local(2007, 7, 1), time.end
|
1253
|
+
|
1254
|
+
time = parse_now(string, :guess => false, :context => :past)
|
1255
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
1256
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
1257
|
+
|
1258
|
+
time = parse_now("#{string} 2005", :guess => false)
|
1259
|
+
assert_equal Time.local(2005, 4, 1), time.begin
|
1260
|
+
assert_equal Time.local(2005, 7, 1), time.end
|
1261
|
+
|
1262
|
+
time = parse_now("2005 #{string}", :guess => false)
|
1263
|
+
assert_equal Time.local(2005, 4, 1), time.begin
|
1264
|
+
assert_equal Time.local(2005, 7, 1), time.end
|
1265
|
+
|
1266
|
+
time = parse_now("#{string} this year", :guess => false)
|
1267
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
1268
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
1269
|
+
|
1270
|
+
time = parse_now("this year #{string}", :guess => false)
|
1271
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
1272
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
1273
|
+
|
1274
|
+
time = parse_now("#{string} next year", :guess => false)
|
1275
|
+
assert_equal Time.local(2007, 4, 1), time.begin
|
1276
|
+
assert_equal Time.local(2007, 7, 1), time.end
|
1277
|
+
|
1278
|
+
time = parse_now("next year #{string}", :guess => false)
|
1279
|
+
assert_equal Time.local(2007, 4, 1), time.begin
|
1280
|
+
assert_equal Time.local(2007, 7, 1), time.end
|
1281
|
+
|
1282
|
+
time = parse_now("this #{string}", :guess => false, context: :none)
|
1283
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
1284
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
1285
|
+
|
1286
|
+
time = parse_now("last #{string}", :guess => false, context: :none)
|
1287
|
+
assert_equal Time.local(2006, 4, 1), time.begin
|
1288
|
+
assert_equal Time.local(2006, 7, 1), time.end
|
1289
|
+
|
1290
|
+
time = parse_now("next #{string}", :guess => false, context: :none)
|
1291
|
+
assert_equal Time.local(2007, 4, 1), time.begin
|
1292
|
+
assert_equal Time.local(2007, 7, 1), time.end
|
1293
|
+
end
|
1294
|
+
|
1295
|
+
["Q3", "third quarter", "3rd quarter"].each do |string|
|
1296
|
+
time = parse_now(string, :guess => false, :context => :none)
|
1297
|
+
assert_equal Time.local(2006, 7, 1), time.begin
|
1298
|
+
assert_equal Time.local(2006, 10, 1), time.end
|
1299
|
+
|
1300
|
+
time = parse_now(string, :guess => false, :context => :future)
|
1301
|
+
assert_equal Time.local(2007, 7, 1), time.begin
|
1302
|
+
assert_equal Time.local(2007, 10, 1), time.end
|
1303
|
+
|
1304
|
+
time = parse_now(string, :guess => false, :context => :past)
|
1305
|
+
assert_equal Time.local(2005, 7, 1), time.begin
|
1306
|
+
assert_equal Time.local(2005, 10, 1), time.end
|
1307
|
+
|
1308
|
+
time = parse_now("#{string} 2005", :guess => false)
|
1309
|
+
assert_equal Time.local(2005, 7, 1), time.begin
|
1310
|
+
assert_equal Time.local(2005, 10, 1), time.end
|
1311
|
+
|
1312
|
+
time = parse_now("2005 #{string}", :guess => false)
|
1313
|
+
assert_equal Time.local(2005, 7, 1), time.begin
|
1314
|
+
assert_equal Time.local(2005, 10, 1), time.end
|
1315
|
+
|
1316
|
+
time = parse_now("#{string} this year", :guess => false, context: :none)
|
1317
|
+
assert_equal Time.local(2006, 7, 1), time.begin
|
1318
|
+
assert_equal Time.local(2006, 10, 1), time.end
|
1319
|
+
|
1320
|
+
time = parse_now("this year #{string}", :guess => false, context: :none)
|
1321
|
+
assert_equal Time.local(2006, 7, 1), time.begin
|
1322
|
+
assert_equal Time.local(2006, 10, 1), time.end
|
1323
|
+
|
1324
|
+
time = parse_now("#{string} next year", :guess => false)
|
1325
|
+
assert_equal Time.local(2007, 7, 1), time.begin
|
1326
|
+
assert_equal Time.local(2007, 10, 1), time.end
|
1327
|
+
|
1328
|
+
time = parse_now("next year #{string}", :guess => false)
|
1329
|
+
assert_equal Time.local(2007, 7, 1), time.begin
|
1330
|
+
assert_equal Time.local(2007, 10, 1), time.end
|
1331
|
+
|
1332
|
+
time = parse_now("this #{string}", :guess => false, context: :none)
|
1333
|
+
assert_equal Time.local(2006, 7, 1), time.begin
|
1334
|
+
assert_equal Time.local(2006, 10, 1), time.end
|
1335
|
+
|
1336
|
+
time = parse_now("last #{string}", :guess => false, context: :none)
|
1337
|
+
assert_equal Time.local(2005, 7, 1), time.begin
|
1338
|
+
assert_equal Time.local(2005, 10, 1), time.end
|
1339
|
+
|
1340
|
+
time = parse_now("next #{string}", :guess => false, context: :none)
|
1341
|
+
assert_equal Time.local(2007, 7, 1), time.begin
|
1342
|
+
assert_equal Time.local(2007, 10, 1), time.end
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
["Q4", "fourth quarter", "4th quarter"].each do |string|
|
1346
|
+
time = parse_now(string, :guess => false, :context => :none)
|
1347
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
1348
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
1349
|
+
|
1350
|
+
time = parse_now(string, :guess => false, :context => :future)
|
1351
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
1352
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
1353
|
+
|
1354
|
+
time = parse_now(string, :guess => false, :context => :past)
|
1355
|
+
assert_equal Time.local(2005, 10, 1), time.begin
|
1356
|
+
assert_equal Time.local(2006, 1, 1), time.end
|
1357
|
+
|
1358
|
+
time = parse_now("#{string} 2005", :guess => false)
|
1359
|
+
assert_equal Time.local(2005, 10, 1), time.begin
|
1360
|
+
assert_equal Time.local(2006, 1, 1), time.end
|
1361
|
+
|
1362
|
+
time = parse_now("2005 #{string}", :guess => false)
|
1363
|
+
assert_equal Time.local(2005, 10, 1), time.begin
|
1364
|
+
assert_equal Time.local(2006, 1, 1), time.end
|
1365
|
+
|
1366
|
+
time = parse_now("#{string} this year", :guess => false)
|
1367
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
1368
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
1369
|
+
|
1370
|
+
time = parse_now("this year #{string}", :guess => false)
|
1371
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
1372
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
1373
|
+
|
1374
|
+
time = parse_now("#{string} next year", :guess => false)
|
1375
|
+
assert_equal Time.local(2007, 10, 1), time.begin
|
1376
|
+
assert_equal Time.local(2008, 1, 1), time.end
|
1377
|
+
|
1378
|
+
time = parse_now("next year #{string}", :guess => false)
|
1379
|
+
assert_equal Time.local(2007, 10, 1), time.begin
|
1380
|
+
assert_equal Time.local(2008, 1, 1), time.end
|
1381
|
+
|
1382
|
+
time = parse_now("this #{string}", :guess => false, context: :none)
|
1383
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
1384
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
1385
|
+
|
1386
|
+
time = parse_now("last #{string}", :guess => false, context: :none)
|
1387
|
+
assert_equal Time.local(2005, 10, 1), time.begin
|
1388
|
+
assert_equal Time.local(2006, 1, 1), time.end
|
1389
|
+
|
1390
|
+
time = parse_now("next #{string}", :guess => false, context: :none)
|
1391
|
+
assert_equal Time.local(2006, 10, 1), time.begin
|
1392
|
+
assert_equal Time.local(2007, 1, 1), time.end
|
1393
|
+
end
|
1394
|
+
end
|
1395
|
+
|
1396
|
+
# regression
|
1397
|
+
|
1398
|
+
# def test_partial
|
1399
|
+
# assert_equal '', parse_now("2 hours")
|
1400
|
+
# end
|
1401
|
+
|
1402
|
+
def test_days_in_november
|
1403
|
+
t1 = Chronic.parse('1st thursday in november', :now => Time.local(2007))
|
1404
|
+
assert_equal Time.local(2007, 11, 1, 12), t1
|
1405
|
+
|
1406
|
+
t1 = Chronic.parse('1st friday in november', :now => Time.local(2007))
|
1407
|
+
assert_equal Time.local(2007, 11, 2, 12), t1
|
1408
|
+
|
1409
|
+
t1 = Chronic.parse('1st saturday in november', :now => Time.local(2007))
|
1410
|
+
assert_equal Time.local(2007, 11, 3, 12), t1
|
1411
|
+
|
1412
|
+
t1 = Chronic.parse('1st sunday in november', :now => Time.local(2007))
|
1413
|
+
assert_equal Time.local(2007, 11, 4, 12), t1
|
1414
|
+
|
1415
|
+
t1 = Chronic.parse('1st monday in november', :now => Time.local(2007))
|
1416
|
+
assert_equal Time.local(2007, 11, 5, 12), t1
|
1417
|
+
end
|
1418
|
+
|
1419
|
+
def test_now_changes
|
1420
|
+
t1 = Chronic.parse("now")
|
1421
|
+
sleep 0.1
|
1422
|
+
t2 = Chronic.parse("now")
|
1423
|
+
refute_equal t1, t2
|
1424
|
+
end
|
1425
|
+
|
1426
|
+
def test_noon
|
1427
|
+
t1 = Chronic.parse('2011-01-01 at noon', :ambiguous_time_range => :none)
|
1428
|
+
assert_equal Time.local(2011, 1, 1, 12, 0), t1
|
1429
|
+
end
|
1430
|
+
|
1431
|
+
def test_handle_rdn_rmn_sd
|
1432
|
+
time = parse_now("Thu Aug 10")
|
1433
|
+
assert_equal Time.local(2006, 8, 10, 12), time
|
1434
|
+
|
1435
|
+
time = parse_now("Thursday July 31")
|
1436
|
+
assert_equal Time.local(2008, 7, 31, 12), time
|
1437
|
+
|
1438
|
+
time = parse_now("Thursday December 31")
|
1439
|
+
assert_equal Time.local(2009, 12, 31, 12), time
|
1440
|
+
end
|
1441
|
+
|
1442
|
+
def test_handle_rdn_rmn_sd_rt
|
1443
|
+
time = parse_now("Thu Aug 10 4pm")
|
1444
|
+
assert_equal Time.local(2006, 8, 10, 16, 30), time
|
1445
|
+
|
1446
|
+
time = parse_now("Thu Aug 10 at 4pm")
|
1447
|
+
assert_equal Time.local(2006, 8, 10, 16, 30), time
|
1448
|
+
end
|
1449
|
+
|
1450
|
+
def test_handle_rdn_rmn_od_rt
|
1451
|
+
time = parse_now("Thu Aug 10th at 4pm")
|
1452
|
+
assert_equal Time.local(2006, 8, 10, 16, 30), time
|
1453
|
+
end
|
1454
|
+
|
1455
|
+
def test_handle_rdn_od_rt
|
1456
|
+
time = parse_now("Thu 17th at 4pm")
|
1457
|
+
assert_equal Time.local(2006, 8, 17, 16, 30), time
|
1458
|
+
|
1459
|
+
time = parse_now("Sat 16th at 4pm", :guess => :begin)
|
1460
|
+
assert_equal Time.local(2006, 9, 16, 16), time
|
1461
|
+
|
1462
|
+
time = parse_now("Thu 1st at 4pm")
|
1463
|
+
assert_equal Time.local(2007, 2, 1, 16, 30), time
|
1464
|
+
|
1465
|
+
time = parse_now("Tue 1st at 4pm", :context => :past)
|
1466
|
+
assert_equal Time.local(2006, 8, 1, 16, 30), time
|
1467
|
+
end
|
1468
|
+
|
1469
|
+
def test_handle_rdn_od
|
1470
|
+
time = parse_now("Thu 17th")
|
1471
|
+
assert_equal Time.local(2006, 8, 17, 12), time
|
1472
|
+
end
|
1473
|
+
|
1474
|
+
def test_handle_rdn_rmn_sd_sy
|
1475
|
+
time = parse_now("Thu Aug 10 2006")
|
1476
|
+
assert_equal Time.local(2006, 8, 10, 12), time
|
1477
|
+
|
1478
|
+
time = parse_now("Mon July 31 2006", :context => :past)
|
1479
|
+
assert_equal Time.local(2006, 7, 31, 12), time
|
1480
|
+
|
1481
|
+
time = parse_now("Sun December 31 2006")
|
1482
|
+
assert_equal Time.local(2006, 12, 31, 12), time
|
1483
|
+
|
1484
|
+
time = parse_now("Sat December 30 2006")
|
1485
|
+
assert_equal Time.local(2006, 12, 30, 12), time
|
1486
|
+
end
|
1487
|
+
|
1488
|
+
def test_handle_rdn_rmn_od
|
1489
|
+
time = parse_now("Thu Aug 10th")
|
1490
|
+
assert_equal Time.local(2006, 8, 10, 12), time
|
1491
|
+
|
1492
|
+
time = parse_now("Monday July 31st", :context => :past)
|
1493
|
+
assert_equal Time.local(2006, 7, 31, 12), time
|
1494
|
+
|
1495
|
+
time = parse_now("Sun December 31st")
|
1496
|
+
assert_equal Time.local(2006, 12, 31, 12), time
|
1497
|
+
end
|
1498
|
+
|
1499
|
+
def test_handle_rdn_rmn_od_sy
|
1500
|
+
time = parse_now("Wed Aug 10th 2005")
|
1501
|
+
assert_equal Time.local(2005, 8, 10, 12), time
|
1502
|
+
|
1503
|
+
time = parse_now("Sun July 31st 2005")
|
1504
|
+
assert_equal Time.local(2005, 7, 31, 12), time
|
1505
|
+
|
1506
|
+
time = parse_now("Sat December 31st 2005")
|
1507
|
+
assert_equal Time.local(2005, 12, 31, 12), time
|
1508
|
+
|
1509
|
+
time = parse_now("Fr December 30th 2005")
|
1510
|
+
assert_equal Time.local(2005, 12, 30, 12), time
|
1511
|
+
end
|
1512
|
+
|
1513
|
+
private
|
1514
|
+
def parse_now(string, options={})
|
1515
|
+
Chronic.parse(string, {:now => TIME_2006_08_16_14_00_00 }.merge(options))
|
1516
|
+
end
|
1517
|
+
def pre_normalize(s)
|
1518
|
+
Chronic::Parser.new.pre_normalize s
|
1519
|
+
end
|
1520
|
+
end
|