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