chronic 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.md +11 -0
- data/README.md +38 -45
- data/lib/chronic.rb +97 -69
- data/lib/chronic/handler.rb +7 -7
- data/lib/chronic/handlers.rb +68 -21
- data/lib/chronic/{chronic.rb → parser.rb} +52 -134
- data/lib/chronic/repeater.rb +11 -11
- data/lib/chronic/separator.rb +15 -1
- data/test/test_chronic.rb +9 -27
- data/test/test_handler.rb +17 -13
- data/test/test_numerizer.rb +1 -1
- data/test/test_parsing.rb +112 -18
- metadata +4 -3
data/test/test_numerizer.rb
CHANGED
@@ -62,7 +62,7 @@ class ParseNumbersTest < TestCase
|
|
62
62
|
}.each do |key, val|
|
63
63
|
# Use pre_normalize here instead of Numerizer directly because
|
64
64
|
# pre_normalize deals with parsing 'second' appropriately
|
65
|
-
assert_equal val, Chronic.pre_normalize(key)
|
65
|
+
assert_equal val, Chronic::Parser.new.pre_normalize(key)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
data/test/test_parsing.rb
CHANGED
@@ -9,11 +9,21 @@ class TestParsing < TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_handle_generic
|
12
|
-
time = Chronic.parse("2012-08-
|
13
|
-
assert_equal Time.local(2012, 8, 2,
|
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
|
14
20
|
|
15
21
|
time = Chronic.parse("2012-08-02T12:00:00Z")
|
16
22
|
assert_equal Time.utc(2012, 8, 2, 12), time
|
23
|
+
|
24
|
+
time = Chronic.parse("2012-01-03 01:00:00.100")
|
25
|
+
time2 = Time.parse("2012-01-03 01:00:00.100")
|
26
|
+
assert_equal time, time2
|
17
27
|
end
|
18
28
|
|
19
29
|
def test_handle_rmn_sd
|
@@ -23,9 +33,15 @@ class TestParsing < TestCase
|
|
23
33
|
time = parse_now("aug 3", :context => :past)
|
24
34
|
assert_equal Time.local(2006, 8, 3, 12), time
|
25
35
|
|
36
|
+
time = parse_now("aug. 3")
|
37
|
+
assert_equal Time.local(2006, 8, 3, 12), time
|
38
|
+
|
26
39
|
time = parse_now("aug 20")
|
27
40
|
assert_equal Time.local(2006, 8, 20, 12), time
|
28
41
|
|
42
|
+
time = parse_now("aug-20")
|
43
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
44
|
+
|
29
45
|
time = parse_now("aug 20", :context => :future)
|
30
46
|
assert_equal Time.local(2006, 8, 20, 12), time
|
31
47
|
|
@@ -98,6 +114,12 @@ class TestParsing < TestCase
|
|
98
114
|
time = parse_now("22 February")
|
99
115
|
assert_equal Time.local(2007, 2, 22, 12), time
|
100
116
|
|
117
|
+
time = parse_now("22 feb")
|
118
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
119
|
+
|
120
|
+
time = parse_now("22-feb")
|
121
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
122
|
+
|
101
123
|
time = parse_now("31 of may at 6:30pm")
|
102
124
|
assert_equal Time.local(2007, 5, 31, 18, 30), time
|
103
125
|
|
@@ -182,6 +204,9 @@ class TestParsing < TestCase
|
|
182
204
|
|
183
205
|
time = parse_now("may 27 32")
|
184
206
|
assert_equal Time.local(2032, 5, 27, 12, 0, 0), time
|
207
|
+
|
208
|
+
time = parse_now("oct 5 2012 1045pm")
|
209
|
+
assert_equal Time.local(2012, 10, 5, 22, 45), time
|
185
210
|
end
|
186
211
|
|
187
212
|
def test_handle_rmn_od_sy
|
@@ -302,19 +327,29 @@ class TestParsing < TestCase
|
|
302
327
|
|
303
328
|
def test_handle_sm_sd
|
304
329
|
time = parse_now("05/06")
|
305
|
-
assert_equal Time.local(
|
330
|
+
assert_equal Time.local(2007, 5, 6, 12), time
|
306
331
|
|
307
332
|
time = parse_now("05/06", :endian_precedence => [:little, :medium])
|
308
|
-
assert_equal Time.local(
|
333
|
+
assert_equal Time.local(2007, 6, 5, 12), time
|
309
334
|
|
310
335
|
time = parse_now("05/06 6:05:57 PM")
|
311
|
-
assert_equal Time.local(
|
336
|
+
assert_equal Time.local(2007, 5, 6, 18, 05, 57), time
|
312
337
|
|
313
338
|
time = parse_now("05/06 6:05:57 PM", :endian_precedence => [:little, :medium])
|
314
|
-
assert_equal Time.local(
|
339
|
+
assert_equal Time.local(2007, 6, 5, 18, 05, 57), time
|
340
|
+
|
341
|
+
time = parse_now("13/09")
|
342
|
+
assert_equal Time.local(2006, 9, 13, 12), time
|
343
|
+
|
344
|
+
# future
|
345
|
+
time = parse_now("05/06") # future is default context
|
346
|
+
assert_equal Time.local(2007, 5, 6, 12), time
|
347
|
+
|
348
|
+
time = parse_now("1/13", :context => :future)
|
349
|
+
assert_equal Time.local(2007, 1, 13, 12), time
|
315
350
|
|
316
|
-
time = parse_now("13
|
317
|
-
assert_equal Time.local(2006,
|
351
|
+
time = parse_now("3/13", :context => :none)
|
352
|
+
assert_equal Time.local(2006, 3, 13, 12), time
|
318
353
|
end
|
319
354
|
|
320
355
|
# def test_handle_sm_sy
|
@@ -402,6 +437,9 @@ class TestParsing < TestCase
|
|
402
437
|
def test_handle_sm_rmn_sy
|
403
438
|
time = parse_now('30-Mar-11')
|
404
439
|
assert_equal Time.local(2011, 3, 30, 12), time
|
440
|
+
|
441
|
+
time = parse_now('31-Aug-12')
|
442
|
+
assert_equal Time.local(2012, 8, 31), time
|
405
443
|
end
|
406
444
|
|
407
445
|
# end of testing handlers
|
@@ -834,6 +872,16 @@ class TestParsing < TestCase
|
|
834
872
|
|
835
873
|
time = Chronic.parse("2 months ago", :now => Time.parse("2007-03-07 23:30"))
|
836
874
|
assert_equal Time.local(2007, 1, 7, 23, 30), time
|
875
|
+
|
876
|
+
# Two repeaters
|
877
|
+
time = parse_now("25 minutes and 20 seconds from now")
|
878
|
+
assert_equal Time.local(2006, 8, 16, 14, 25, 20), time
|
879
|
+
|
880
|
+
time = parse_now("24 hours and 20 minutes from now")
|
881
|
+
assert_equal Time.local(2006, 8, 17, 14, 20, 0), time
|
882
|
+
|
883
|
+
time = parse_now("24 hours 20 minutes from now")
|
884
|
+
assert_equal Time.local(2006, 8, 17, 14, 20, 0), time
|
837
885
|
end
|
838
886
|
|
839
887
|
def test_parse_guess_p_s_r
|
@@ -923,6 +971,27 @@ class TestParsing < TestCase
|
|
923
971
|
assert_equal parse_now("second monday in january"), parse_now("2nd monday in january")
|
924
972
|
end
|
925
973
|
|
974
|
+
def test_relative_to_an_hour_before
|
975
|
+
# example prenormalization "10 to 2" becomes "10 minutes past 2"
|
976
|
+
assert_equal Time.local(2006, 8, 16, 13, 50), parse_now("10 to 2")
|
977
|
+
assert_equal Time.local(2006, 8, 16, 13, 50), parse_now("10 till 2")
|
978
|
+
assert_equal Time.local(2006, 8, 16, 13, 50), parse_now("10 prior to 2")
|
979
|
+
assert_equal Time.local(2006, 8, 16, 13, 50), parse_now("10 before 2")
|
980
|
+
|
981
|
+
# uses the current hour, so 2006-08-16 13:50:00, not 14:50
|
982
|
+
assert_equal Time.local(2006, 8, 16, 13, 50), parse_now("10 to")
|
983
|
+
assert_equal Time.local(2006, 8, 16, 13, 50), parse_now("10 till")
|
984
|
+
|
985
|
+
assert_equal Time.local(2006, 8, 16, 15, 45), parse_now("quarter to 4")
|
986
|
+
end
|
987
|
+
|
988
|
+
def test_relative_to_an_hour_after
|
989
|
+
# not nil
|
990
|
+
assert_equal Time.local(2006, 8, 16, 14, 10), parse_now("10 after 2")
|
991
|
+
assert_equal Time.local(2006, 8, 16, 14, 10), parse_now("10 past 2")
|
992
|
+
assert_equal Time.local(2006, 8, 16, 14, 30), parse_now("half past 2")
|
993
|
+
end
|
994
|
+
|
926
995
|
def test_parse_only_complete_pointers
|
927
996
|
assert_equal parse_now("eat pasty buns today at 2pm"), @time_2006_08_16_14_00_00
|
928
997
|
assert_equal parse_now("futuristically speaking today at 2pm"), @time_2006_08_16_14_00_00
|
@@ -939,16 +1008,6 @@ class TestParsing < TestCase
|
|
939
1008
|
assert_equal Time.local(2006, 8, 16, 18, 30), parse_now("8/16/2006 at 6:30p")
|
940
1009
|
end
|
941
1010
|
|
942
|
-
def test_argument_validation
|
943
|
-
assert_raises(ArgumentError) do
|
944
|
-
time = Chronic.parse("may 27", :foo => :bar)
|
945
|
-
end
|
946
|
-
|
947
|
-
assert_raises(ArgumentError) do
|
948
|
-
time = Chronic.parse("may 27", :context => :bar)
|
949
|
-
end
|
950
|
-
end
|
951
|
-
|
952
1011
|
def test_seasons
|
953
1012
|
t = parse_now("this spring", :guess => false)
|
954
1013
|
assert_equal Time.local(2007, 3, 20), t.begin
|
@@ -1019,6 +1078,38 @@ class TestParsing < TestCase
|
|
1019
1078
|
assert_equal Time.local(2006, 12, 31, 12), time
|
1020
1079
|
end
|
1021
1080
|
|
1081
|
+
def test_handle_rdn_rmn_sd_rt
|
1082
|
+
time = parse_now("Thu Aug 10 4pm")
|
1083
|
+
assert_equal Time.local(2006, 8, 10, 16), time
|
1084
|
+
|
1085
|
+
time = parse_now("Thu Aug 10 at 4pm")
|
1086
|
+
assert_equal Time.local(2006, 8, 10, 16), time
|
1087
|
+
end
|
1088
|
+
|
1089
|
+
def test_handle_rdn_rmn_od_rt
|
1090
|
+
time = parse_now("Thu Aug 10th at 4pm")
|
1091
|
+
assert_equal Time.local(2006, 8, 10, 16), time
|
1092
|
+
end
|
1093
|
+
|
1094
|
+
def test_handle_rdn_od_rt
|
1095
|
+
time = parse_now("Thu 17th at 4pm")
|
1096
|
+
assert_equal Time.local(2006, 8, 17, 16), time
|
1097
|
+
|
1098
|
+
time = parse_now("Thu 16th at 4pm")
|
1099
|
+
assert_equal Time.local(2006, 8, 16, 16), time
|
1100
|
+
|
1101
|
+
time = parse_now("Thu 1st at 4pm")
|
1102
|
+
assert_equal Time.local(2006, 9, 1, 16), time
|
1103
|
+
|
1104
|
+
time = parse_now("Thu 1st at 4pm", :context => :past)
|
1105
|
+
assert_equal Time.local(2006, 8, 1, 16), time
|
1106
|
+
end
|
1107
|
+
|
1108
|
+
def test_handle_rdn_od
|
1109
|
+
time = parse_now("Thu 17th")
|
1110
|
+
assert_equal Time.local(2006, 8, 17, 12), time
|
1111
|
+
end
|
1112
|
+
|
1022
1113
|
def test_handle_rdn_rmn_sd_sy
|
1023
1114
|
time = parse_now("Thu Aug 10 2006")
|
1024
1115
|
assert_equal Time.local(2006, 8, 10, 12), time
|
@@ -1048,4 +1139,7 @@ class TestParsing < TestCase
|
|
1048
1139
|
def parse_now(string, options={})
|
1049
1140
|
Chronic.parse(string, {:now => TIME_2006_08_16_14_00_00 }.merge(options))
|
1050
1141
|
end
|
1142
|
+
def pre_normalize(s)
|
1143
|
+
Chronic::Parser.new.pre_normalize s
|
1144
|
+
end
|
1051
1145
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -62,13 +62,13 @@ files:
|
|
62
62
|
- Rakefile
|
63
63
|
- chronic.gemspec
|
64
64
|
- lib/chronic.rb
|
65
|
-
- lib/chronic/chronic.rb
|
66
65
|
- lib/chronic/grabber.rb
|
67
66
|
- lib/chronic/handler.rb
|
68
67
|
- lib/chronic/handlers.rb
|
69
68
|
- lib/chronic/mini_date.rb
|
70
69
|
- lib/chronic/numerizer.rb
|
71
70
|
- lib/chronic/ordinal.rb
|
71
|
+
- lib/chronic/parser.rb
|
72
72
|
- lib/chronic/pointer.rb
|
73
73
|
- lib/chronic/repeater.rb
|
74
74
|
- lib/chronic/repeaters/repeater_day.rb
|
@@ -164,3 +164,4 @@ test_files:
|
|
164
164
|
- test/test_repeater_year.rb
|
165
165
|
- test/test_span.rb
|
166
166
|
- test/test_token.rb
|
167
|
+
has_rdoc:
|