chronic 0.4.1 → 0.5.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/.gemtest +0 -0
- data/.gitignore +5 -0
- data/.yardopts +3 -0
- data/HISTORY.md +36 -2
- data/Manifest.txt +6 -2
- data/README.md +8 -2
- data/Rakefile +9 -101
- data/chronic.gemspec +12 -78
- data/lib/chronic/chronic.rb +225 -91
- data/lib/chronic/grabber.rb +12 -3
- data/lib/chronic/handlers.rb +94 -198
- data/lib/chronic/mini_date.rb +6 -2
- data/lib/chronic/ordinal.rb +15 -4
- data/lib/chronic/pointer.rb +12 -3
- data/lib/chronic/repeater.rb +28 -9
- data/lib/chronic/repeaters/repeater_day.rb +0 -1
- data/lib/chronic/repeaters/repeater_day_name.rb +0 -1
- data/lib/chronic/repeaters/repeater_day_portion.rb +0 -1
- data/lib/chronic/repeaters/repeater_fortnight.rb +0 -1
- data/lib/chronic/repeaters/repeater_hour.rb +0 -1
- data/lib/chronic/repeaters/repeater_minute.rb +0 -1
- data/lib/chronic/repeaters/repeater_month.rb +13 -2
- data/lib/chronic/repeaters/repeater_month_name.rb +13 -21
- data/lib/chronic/repeaters/repeater_season.rb +0 -19
- data/lib/chronic/repeaters/repeater_season_name.rb +0 -2
- data/lib/chronic/repeaters/repeater_second.rb +0 -1
- data/lib/chronic/repeaters/repeater_time.rb +1 -2
- data/lib/chronic/repeaters/repeater_week.rb +0 -1
- data/lib/chronic/repeaters/repeater_weekday.rb +0 -1
- data/lib/chronic/repeaters/repeater_weekend.rb +0 -1
- data/lib/chronic/repeaters/repeater_year.rb +19 -8
- data/lib/chronic/scalar.rb +29 -1
- data/lib/chronic/season.rb +37 -0
- data/lib/chronic/separator.rb +24 -7
- data/lib/chronic/tag.rb +10 -1
- data/lib/chronic/time_zone.rb +12 -3
- data/lib/chronic/token.rb +14 -4
- data/lib/chronic.rb +62 -49
- data/test/test_Chronic.rb +52 -2
- data/test/test_RepeaterMonth.rb +4 -0
- data/test/test_RepeaterSeason.rb +40 -0
- data/test/test_RepeaterYear.rb +7 -0
- data/test/test_Time.rb +1 -1
- data/test/test_parsing.rb +159 -113
- metadata +31 -29
- data/benchmark/benchmark.rb +0 -13
data/test/test_Chronic.rb
CHANGED
|
@@ -21,7 +21,7 @@ class TestChronic < Test::Unit::TestCase
|
|
|
21
21
|
|
|
22
22
|
assert_equal :morning, tokens[1].tags[0].type
|
|
23
23
|
|
|
24
|
-
tokens = Chronic.dealias_and_disambiguate_times(tokens, {})
|
|
24
|
+
tokens = Chronic::Handlers.dealias_and_disambiguate_times(tokens, {})
|
|
25
25
|
|
|
26
26
|
assert_equal :am, tokens[1].tags[0].type
|
|
27
27
|
assert_equal 2, tokens.size
|
|
@@ -34,7 +34,7 @@ class TestChronic < Test::Unit::TestCase
|
|
|
34
34
|
|
|
35
35
|
assert_equal :morning, tokens[1].tags[0].type
|
|
36
36
|
|
|
37
|
-
tokens = Chronic.dealias_and_disambiguate_times(tokens, {})
|
|
37
|
+
tokens = Chronic::Handlers.dealias_and_disambiguate_times(tokens, {})
|
|
38
38
|
|
|
39
39
|
assert_equal :morning, tokens[1].tags[0].type
|
|
40
40
|
assert_equal 2, tokens.size
|
|
@@ -51,4 +51,54 @@ class TestChronic < Test::Unit::TestCase
|
|
|
51
51
|
assert_equal Time.local(2006, 11, 16), Chronic.guess(span)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
def test_now
|
|
55
|
+
Chronic.parse('now', :now => Time.local(2006, 01))
|
|
56
|
+
assert_equal Time.local(2006, 01), Chronic.now
|
|
57
|
+
|
|
58
|
+
Chronic.parse('now', :now => Time.local(2007, 01))
|
|
59
|
+
assert_equal Time.local(2007, 01), Chronic.now
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_endian_definitions
|
|
63
|
+
# middle, little
|
|
64
|
+
endians = [
|
|
65
|
+
Chronic::Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_day, :separator_slash_or_dash, :scalar_year, :separator_at?, 'time?'], :handle_sm_sd_sy),
|
|
66
|
+
Chronic::Handler.new([:scalar_day, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_year, :separator_at?, 'time?'], :handle_sd_sm_sy)
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
assert_equal endians, Chronic.definitions[:endian]
|
|
70
|
+
|
|
71
|
+
defs = Chronic.definitions(:endian_precedence => :little)
|
|
72
|
+
assert_equal endians.reverse, defs[:endian]
|
|
73
|
+
|
|
74
|
+
defs = Chronic.definitions(:endian_precedence => [:little, :middle])
|
|
75
|
+
assert_equal endians.reverse, defs[:endian]
|
|
76
|
+
|
|
77
|
+
assert_raises(Chronic::InvalidArgumentException) do
|
|
78
|
+
Chronic.definitions(:endian_precedence => :invalid)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_passing_options
|
|
83
|
+
assert_raises(Chronic::InvalidArgumentException) do
|
|
84
|
+
Chronic.parse('now', :invalid => :option)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
assert_raises(Chronic::InvalidArgumentException) do
|
|
88
|
+
Chronic.parse('now', :context => :invalid_context)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_debug
|
|
93
|
+
require 'stringio'
|
|
94
|
+
$stdout = StringIO.new
|
|
95
|
+
Chronic.debug = true
|
|
96
|
+
|
|
97
|
+
Chronic.parse 'now'
|
|
98
|
+
assert $stdout.string.include?('this(grabber-this)')
|
|
99
|
+
ensure
|
|
100
|
+
$stdout = STDOUT
|
|
101
|
+
Chronic.debug = false
|
|
102
|
+
end
|
|
103
|
+
|
|
54
104
|
end
|
data/test/test_RepeaterMonth.rb
CHANGED
|
@@ -23,6 +23,10 @@ class TestRepeaterMonth < Test::Unit::TestCase
|
|
|
23
23
|
|
|
24
24
|
time = Chronic::RepeaterMonth.new(:month).offset_by(@now, 10, :past)
|
|
25
25
|
assert_equal Time.local(2005, 10, 16, 14), time
|
|
26
|
+
|
|
27
|
+
time = Chronic::RepeaterMonth.new(:month).offset_by(Time.local(2010, 3, 29), 1, :past)
|
|
28
|
+
assert_equal 2, time.month
|
|
29
|
+
assert_equal 28, time.day
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
def test_offset
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[helper])
|
|
2
|
+
|
|
3
|
+
class TestRepeaterSeason < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_next_future
|
|
10
|
+
seasons = Chronic::RepeaterSeason.new(:season)
|
|
11
|
+
seasons.start = @now
|
|
12
|
+
|
|
13
|
+
next_season = seasons.next(:future)
|
|
14
|
+
assert_equal Time.local(2006, 9, 23), next_season.begin
|
|
15
|
+
assert_equal Time.local(2006, 12, 21), next_season.end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_next_past
|
|
19
|
+
seasons = Chronic::RepeaterSeason.new(:season)
|
|
20
|
+
seasons.start = @now
|
|
21
|
+
|
|
22
|
+
last_season = seasons.next(:past)
|
|
23
|
+
assert_equal Time.local(2006, 3, 20), last_season.begin
|
|
24
|
+
assert_equal Time.local(2006, 6, 20), last_season.end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_this
|
|
28
|
+
seasons = Chronic::RepeaterSeason.new(:season)
|
|
29
|
+
seasons.start = @now
|
|
30
|
+
|
|
31
|
+
this_season = seasons.this(:future)
|
|
32
|
+
assert_equal Time.local(2006, 8, 17), this_season.begin
|
|
33
|
+
assert_equal Time.local(2006, 9, 22), this_season.end
|
|
34
|
+
|
|
35
|
+
this_season = seasons.this(:past)
|
|
36
|
+
assert_equal Time.local(2006, 6, 21), this_season.begin
|
|
37
|
+
assert_equal Time.local(2006, 8, 16), this_season.end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
data/test/test_RepeaterYear.rb
CHANGED
|
@@ -57,6 +57,13 @@ class TestRepeaterYear < Test::Unit::TestCase
|
|
|
57
57
|
|
|
58
58
|
assert_equal Time.local(1996, 8, 16, 14), offset_span.begin
|
|
59
59
|
assert_equal Time.local(1996, 8, 16, 14, 0, 1), offset_span.end
|
|
60
|
+
|
|
61
|
+
now = Time.local(2008, 2, 29)
|
|
62
|
+
span = Chronic::Span.new(now, now + 1)
|
|
63
|
+
offset_span = Chronic::RepeaterYear.new(:year).offset(span, 1, :past)
|
|
64
|
+
|
|
65
|
+
assert_equal Time.local(2007, 2, 28), offset_span.begin
|
|
66
|
+
assert_equal Time.local(2007, 2, 28, 0, 0, 1), offset_span.end
|
|
60
67
|
end
|
|
61
68
|
|
|
62
69
|
end
|
data/test/test_Time.rb
CHANGED
|
@@ -31,7 +31,7 @@ class TestTime < Test::Unit::TestCase
|
|
|
31
31
|
assert_equal Time.local(2006, 2, 1), Time.construct(2006, 1, 32)
|
|
32
32
|
assert_equal Time.local(2006, 3, 5), Time.construct(2006, 2, 33)
|
|
33
33
|
assert_equal Time.local(2004, 3, 4), Time.construct(2004, 2, 33)
|
|
34
|
-
assert_equal Time.local(2000, 3,
|
|
34
|
+
assert_equal Time.local(2000, 3, 4), Time.construct(2000, 2, 33)
|
|
35
35
|
|
|
36
36
|
assert_nothing_raised do
|
|
37
37
|
Time.construct(2006, 1, 56)
|
data/test/test_parsing.rb
CHANGED
|
@@ -8,8 +8,21 @@ class TestParsing < Test::Unit::TestCase
|
|
|
8
8
|
@time_2006_08_16_14_00_00 = TIME_2006_08_16_14_00_00
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def
|
|
12
|
-
|
|
11
|
+
def test_parse_m_d
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_handle_rmn_sd
|
|
15
|
+
time = parse_now("aug 3")
|
|
16
|
+
assert_equal Time.local(2006, 8, 3, 12), time
|
|
17
|
+
|
|
18
|
+
time = parse_now("aug 3", :context => :past)
|
|
19
|
+
assert_equal Time.local(2006, 8, 3, 12), time
|
|
20
|
+
|
|
21
|
+
time = parse_now("aug 20")
|
|
22
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
|
23
|
+
|
|
24
|
+
time = parse_now("aug 20", :context => :future)
|
|
25
|
+
assert_equal Time.local(2006, 8, 20, 12), time
|
|
13
26
|
|
|
14
27
|
time = parse_now("may 27")
|
|
15
28
|
assert_equal Time.local(2007, 5, 27, 12), time
|
|
@@ -25,23 +38,9 @@ class TestParsing < Test::Unit::TestCase
|
|
|
25
38
|
|
|
26
39
|
time = parse_now("may 28 at 5:32.19pm", :context => :past)
|
|
27
40
|
assert_equal Time.local(2006, 5, 28, 17, 32, 19), time
|
|
41
|
+
end
|
|
28
42
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
time = parse_now("aug 3")
|
|
32
|
-
assert_equal Time.local(2006, 8, 3, 12), time
|
|
33
|
-
|
|
34
|
-
time = parse_now("aug 3", :context => :past)
|
|
35
|
-
assert_equal Time.local(2006, 8, 3, 12), time
|
|
36
|
-
|
|
37
|
-
time = parse_now("aug 20")
|
|
38
|
-
assert_equal Time.local(2006, 8, 20, 12), time
|
|
39
|
-
|
|
40
|
-
time = parse_now("aug 20", :context => :future)
|
|
41
|
-
assert_equal Time.local(2006, 8, 20, 12), time
|
|
42
|
-
|
|
43
|
-
# rm_sd_on
|
|
44
|
-
|
|
43
|
+
def test_handle_rmn_sd_on
|
|
45
44
|
time = parse_now("5pm on may 28")
|
|
46
45
|
assert_equal Time.local(2007, 5, 28, 17), time
|
|
47
46
|
|
|
@@ -50,9 +49,9 @@ class TestParsing < Test::Unit::TestCase
|
|
|
50
49
|
|
|
51
50
|
time = parse_now("5 on may 28", :ambiguous_time_range => :none)
|
|
52
51
|
assert_equal Time.local(2007, 5, 28, 05), time
|
|
52
|
+
end
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
def test_handle_rmn_od
|
|
56
55
|
time = parse_now("may 27th")
|
|
57
56
|
assert_equal Time.local(2007, 5, 27, 12), time
|
|
58
57
|
|
|
@@ -67,9 +66,20 @@ class TestParsing < Test::Unit::TestCase
|
|
|
67
66
|
|
|
68
67
|
time = parse_now("may 27th at 5", :ambiguous_time_range => :none)
|
|
69
68
|
assert_equal Time.local(2007, 5, 27, 5), time
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_handle_od_rmn
|
|
72
|
+
time = parse_now("22nd February")
|
|
73
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
time = parse_now("31st of may at 6:30pm")
|
|
76
|
+
assert_equal Time.local(2007, 5, 31, 18, 30), time
|
|
72
77
|
|
|
78
|
+
time = parse_now("11th december 8am")
|
|
79
|
+
assert_equal Time.local(2006, 12, 11, 8), time
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_handle_rmn_od_on
|
|
73
83
|
time = parse_now("5:00 pm may 27th", :context => :past)
|
|
74
84
|
assert_equal Time.local(2006, 5, 27, 17), time
|
|
75
85
|
|
|
@@ -81,16 +91,65 @@ class TestParsing < Test::Unit::TestCase
|
|
|
81
91
|
|
|
82
92
|
time = parse_now("5 on may 27th", :ambiguous_time_range => :none)
|
|
83
93
|
assert_equal Time.local(2007, 5, 27, 5), time
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_handle_rmn_sy
|
|
97
|
+
time = parse_now("may 97")
|
|
98
|
+
assert_equal Time.local(1997, 5, 16, 12), time
|
|
99
|
+
|
|
100
|
+
time = parse_now("may 33", :ambiguous_year_future_bias => 10)
|
|
101
|
+
assert_equal Time.local(2033, 5, 16, 12), time
|
|
102
|
+
|
|
103
|
+
time = parse_now("may 32")
|
|
104
|
+
assert_equal Time.local(2032, 5, 16, 12, 0, 0), time
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_handle_rdn_rmn_sd_t_tz_sy
|
|
108
|
+
time = parse_now("Mon Apr 02 17:00:00 PDT 2007")
|
|
109
|
+
assert_equal 1175558400, time.to_i
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_handle_rmn_sd_sy
|
|
113
|
+
time = parse_now("November 18, 2010")
|
|
114
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
|
115
|
+
|
|
116
|
+
time = parse_now("Jan 1,2010")
|
|
117
|
+
assert_equal Time.local(2010, 1, 1, 12), time
|
|
118
|
+
|
|
119
|
+
time = parse_now("February 14, 2004")
|
|
120
|
+
assert_equal Time.local(2004, 2, 14, 12), time
|
|
121
|
+
|
|
122
|
+
time = parse_now("jan 3 2010")
|
|
123
|
+
assert_equal Time.local(2010, 1, 3, 12), time
|
|
124
|
+
|
|
125
|
+
time = parse_now("jan 3 2010 midnight")
|
|
126
|
+
assert_equal Time.local(2010, 1, 4, 0), time
|
|
127
|
+
|
|
128
|
+
time = parse_now("jan 3 2010 at midnight")
|
|
129
|
+
assert_equal Time.local(2010, 1, 4, 0), time
|
|
130
|
+
|
|
131
|
+
time = parse_now("jan 3 2010 at 4", :ambiguous_time_range => :none)
|
|
132
|
+
assert_equal Time.local(2010, 1, 3, 4), time
|
|
133
|
+
|
|
134
|
+
time = parse_now("may 27, 1979")
|
|
135
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
|
136
|
+
|
|
137
|
+
time = parse_now("may 27 79")
|
|
138
|
+
assert_equal Time.local(1979, 5, 27, 12), time
|
|
84
139
|
|
|
85
|
-
|
|
140
|
+
time = parse_now("may 27 79 4:30")
|
|
141
|
+
assert_equal Time.local(1979, 5, 27, 16, 30), time
|
|
86
142
|
|
|
87
|
-
time = parse_now("
|
|
88
|
-
assert_equal Time.local(1979,
|
|
143
|
+
time = parse_now("may 27 79 at 4:30", :ambiguous_time_range => :none)
|
|
144
|
+
assert_equal Time.local(1979, 5, 27, 4, 30), time
|
|
89
145
|
|
|
90
|
-
time = parse_now("
|
|
91
|
-
assert_equal Time.local(
|
|
146
|
+
time = parse_now("may 27 32")
|
|
147
|
+
assert_equal Time.local(2032, 5, 27, 12, 0, 0), time
|
|
148
|
+
end
|
|
92
149
|
|
|
93
|
-
|
|
150
|
+
def test_handle_rmn_od_sy
|
|
151
|
+
time = parse_now("may 1st 01")
|
|
152
|
+
assert_equal Time.local(2001, 5, 1, 12), time
|
|
94
153
|
|
|
95
154
|
time = parse_now("November 18th 2010")
|
|
96
155
|
assert_equal Time.local(2010, 11, 18, 12), time
|
|
@@ -121,44 +180,17 @@ class TestParsing < Test::Unit::TestCase
|
|
|
121
180
|
|
|
122
181
|
time = parse_now("March 30th 79 at 4:30", :ambiguous_time_range => :none)
|
|
123
182
|
assert_equal Time.local(1979, 3, 30, 4, 30), time
|
|
183
|
+
end
|
|
124
184
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
assert_equal Time.local(2010, 11, 18, 12), time
|
|
129
|
-
|
|
130
|
-
time = parse_now("February 14, 2004")
|
|
131
|
-
assert_equal Time.local(2004, 2, 14, 12), time
|
|
132
|
-
|
|
133
|
-
time = parse_now("jan 3 2010")
|
|
134
|
-
assert_equal Time.local(2010, 1, 3, 12), time
|
|
135
|
-
|
|
136
|
-
time = parse_now("jan 3 2010 midnight")
|
|
137
|
-
assert_equal Time.local(2010, 1, 4, 0), time
|
|
138
|
-
|
|
139
|
-
time = parse_now("jan 3 2010 at midnight")
|
|
140
|
-
assert_equal Time.local(2010, 1, 4, 0), time
|
|
141
|
-
|
|
142
|
-
time = parse_now("jan 3 2010 at 4", :ambiguous_time_range => :none)
|
|
143
|
-
assert_equal Time.local(2010, 1, 3, 4), time
|
|
144
|
-
|
|
145
|
-
#time = parse_now("January 12, '00")
|
|
146
|
-
#assert_equal Time.local(2000, 1, 12, 12), time
|
|
147
|
-
|
|
148
|
-
time = parse_now("may 27, 1979")
|
|
149
|
-
assert_equal Time.local(1979, 5, 27, 12), time
|
|
150
|
-
|
|
151
|
-
time = parse_now("may 27 79")
|
|
152
|
-
assert_equal Time.local(1979, 5, 27, 12), time
|
|
153
|
-
|
|
154
|
-
time = parse_now("may 27 79 4:30")
|
|
155
|
-
assert_equal Time.local(1979, 5, 27, 16, 30), time
|
|
156
|
-
|
|
157
|
-
time = parse_now("may 27 79 at 4:30", :ambiguous_time_range => :none)
|
|
158
|
-
assert_equal Time.local(1979, 5, 27, 4, 30), time
|
|
185
|
+
def test_handle_od_rmn_sy
|
|
186
|
+
time = parse_now("22nd February 2012")
|
|
187
|
+
assert_equal Time.local(2012, 2, 22, 12), time
|
|
159
188
|
|
|
160
|
-
|
|
189
|
+
time = parse_now("11th december 79")
|
|
190
|
+
assert_equal Time.local(1979, 12, 11, 12), time
|
|
191
|
+
end
|
|
161
192
|
|
|
193
|
+
def test_handle_sd_rmn_sy
|
|
162
194
|
time = parse_now("3 jan 2010")
|
|
163
195
|
assert_equal Time.local(2010, 1, 3, 12), time
|
|
164
196
|
|
|
@@ -167,36 +199,25 @@ class TestParsing < Test::Unit::TestCase
|
|
|
167
199
|
|
|
168
200
|
time = parse_now("27 Oct 2006 7:30pm")
|
|
169
201
|
assert_equal Time.local(2006, 10, 27, 19, 30), time
|
|
202
|
+
end
|
|
170
203
|
|
|
171
|
-
|
|
172
|
-
|
|
204
|
+
def test_handle_sm_sd_sy
|
|
173
205
|
time = parse_now("5/27/1979")
|
|
174
206
|
assert_equal Time.local(1979, 5, 27, 12), time
|
|
175
207
|
|
|
176
208
|
time = parse_now("5/27/1979 4am")
|
|
177
209
|
assert_equal Time.local(1979, 5, 27, 4), time
|
|
210
|
+
end
|
|
178
211
|
|
|
179
|
-
|
|
180
|
-
|
|
212
|
+
def test_handle_sd_sm_sy
|
|
181
213
|
time = parse_now("27/5/1979")
|
|
182
214
|
assert_equal Time.local(1979, 5, 27, 12), time
|
|
183
215
|
|
|
184
216
|
time = parse_now("27/5/1979 @ 0700")
|
|
185
217
|
assert_equal Time.local(1979, 5, 27, 7), time
|
|
218
|
+
end
|
|
186
219
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
time = parse_now("05/06")
|
|
190
|
-
assert_equal Time.local(2006, 5, 16, 12), time
|
|
191
|
-
|
|
192
|
-
time = parse_now("12/06")
|
|
193
|
-
assert_equal Time.local(2006, 12, 16, 12), time
|
|
194
|
-
|
|
195
|
-
time = parse_now("13/06")
|
|
196
|
-
assert_equal nil, time
|
|
197
|
-
|
|
198
|
-
# sy_sm_sd
|
|
199
|
-
|
|
220
|
+
def test_handle_sy_sm_sd
|
|
200
221
|
time = parse_now("2000-1-1")
|
|
201
222
|
assert_equal Time.local(2000, 1, 1, 12), time
|
|
202
223
|
|
|
@@ -218,43 +239,73 @@ class TestParsing < Test::Unit::TestCase
|
|
|
218
239
|
time = parse_now("2006-08-20 15:30.30")
|
|
219
240
|
assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
|
|
220
241
|
|
|
221
|
-
|
|
242
|
+
time = parse_now("1902-08-20")
|
|
243
|
+
assert_equal Time.local(1902, 8, 20, 12, 0, 0), time
|
|
244
|
+
end
|
|
222
245
|
|
|
223
|
-
|
|
224
|
-
|
|
246
|
+
def test_handle_sm_sy
|
|
247
|
+
time = parse_now("05/06")
|
|
248
|
+
assert_equal Time.local(2006, 5, 16, 12), time
|
|
249
|
+
|
|
250
|
+
time = parse_now("12/06")
|
|
251
|
+
assert_equal Time.local(2006, 12, 16, 12), time
|
|
252
|
+
|
|
253
|
+
time = parse_now("13/06")
|
|
254
|
+
assert_equal nil, time
|
|
255
|
+
end
|
|
225
256
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
# assert_equal now.to_s, time.to_s
|
|
257
|
+
def test_handle_r
|
|
258
|
+
end
|
|
229
259
|
|
|
230
|
-
|
|
260
|
+
def test_handle_r_g_r
|
|
261
|
+
end
|
|
231
262
|
|
|
232
|
-
|
|
233
|
-
|
|
263
|
+
def test_handle_srp
|
|
264
|
+
end
|
|
234
265
|
|
|
235
|
-
|
|
266
|
+
def test_handle_s_r_p
|
|
267
|
+
end
|
|
236
268
|
|
|
237
|
-
|
|
238
|
-
|
|
269
|
+
def test_handle_p_s_r
|
|
270
|
+
end
|
|
239
271
|
|
|
240
|
-
|
|
241
|
-
|
|
272
|
+
def test_handle_s_r_p_a
|
|
273
|
+
end
|
|
242
274
|
|
|
243
|
-
|
|
244
|
-
assert_equal Time.local(1800, 8, 20, 12, 0, 0), time
|
|
275
|
+
def test_handle_orr
|
|
245
276
|
end
|
|
246
277
|
|
|
247
|
-
def
|
|
248
|
-
time = parse_now("
|
|
249
|
-
assert_equal Time.local(
|
|
278
|
+
def test_handle_o_r_s_r
|
|
279
|
+
time = parse_now("3rd wednesday in november")
|
|
280
|
+
assert_equal Time.local(2006, 11, 15, 12), time
|
|
250
281
|
|
|
251
|
-
time = parse_now("
|
|
252
|
-
assert_equal
|
|
282
|
+
time = parse_now("10th wednesday in november")
|
|
283
|
+
assert_equal nil, time
|
|
284
|
+
|
|
285
|
+
# time = parse_now("3rd wednesday in 2007")
|
|
286
|
+
# assert_equal Time.local(2007, 1, 20, 12), time
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def test_handle_o_r_g_r
|
|
290
|
+
time = parse_now("3rd month next year", :guess => false)
|
|
291
|
+
assert_equal Time.local(2007, 3), time.begin
|
|
292
|
+
|
|
293
|
+
time = parse_now("3rd month next year", :guess => false)
|
|
294
|
+
assert_equal Time.local(2007, 3, 1), time.begin
|
|
295
|
+
|
|
296
|
+
time = parse_now("3rd thursday this september")
|
|
297
|
+
assert_equal Time.local(2006, 9, 21, 12), time
|
|
298
|
+
|
|
299
|
+
now = Time.parse("1/10/2010")
|
|
300
|
+
time = parse_now("3rd thursday this november", :now => now)
|
|
301
|
+
assert_equal Time.local(2010, 11, 18, 12), time
|
|
253
302
|
|
|
254
|
-
time = parse_now("
|
|
255
|
-
assert_equal Time.local(
|
|
303
|
+
time = parse_now("4th day last week")
|
|
304
|
+
assert_equal Time.local(2006, 8, 9, 12), time
|
|
256
305
|
end
|
|
257
306
|
|
|
307
|
+
# end of testing handlers
|
|
308
|
+
|
|
258
309
|
def test_parse_guess_r
|
|
259
310
|
time = parse_now("friday")
|
|
260
311
|
assert_equal Time.local(2006, 8, 18, 12), time
|
|
@@ -274,6 +325,12 @@ class TestParsing < Test::Unit::TestCase
|
|
|
274
325
|
time = parse_now("13:45")
|
|
275
326
|
assert_equal Time.local(2006, 8, 17, 13, 45), time
|
|
276
327
|
|
|
328
|
+
time = parse_now("1:01pm")
|
|
329
|
+
assert_equal Time.local(2006, 8, 16, 13, 01), time
|
|
330
|
+
|
|
331
|
+
time = parse_now("2:01pm")
|
|
332
|
+
assert_equal Time.local(2006, 8, 16, 14, 01), time
|
|
333
|
+
|
|
277
334
|
time = parse_now("november")
|
|
278
335
|
assert_equal Time.local(2006, 11, 16), time
|
|
279
336
|
end
|
|
@@ -643,17 +700,6 @@ class TestParsing < Test::Unit::TestCase
|
|
|
643
700
|
# future
|
|
644
701
|
end
|
|
645
702
|
|
|
646
|
-
def test_parse_guess_o_r_s_r
|
|
647
|
-
time = parse_now("3rd wednesday in november")
|
|
648
|
-
assert_equal Time.local(2006, 11, 15, 12), time
|
|
649
|
-
|
|
650
|
-
time = parse_now("10th wednesday in november")
|
|
651
|
-
assert_equal nil, time
|
|
652
|
-
|
|
653
|
-
# time = parse_now("3rd wednesday in 2007")
|
|
654
|
-
# assert_equal Time.local(2007, 1, 20, 12), time
|
|
655
|
-
end
|
|
656
|
-
|
|
657
703
|
def test_parse_guess_o_r_g_r
|
|
658
704
|
time = parse_now("3rd month next year", :guess => false)
|
|
659
705
|
assert_equal Time.local(2007, 3), time.begin
|
metadata
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chronic
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.5.0
|
|
4
5
|
prerelease:
|
|
5
|
-
version: 0.4.1
|
|
6
6
|
platform: ruby
|
|
7
|
-
authors:
|
|
7
|
+
authors:
|
|
8
8
|
- Tom Preston-Werner
|
|
9
9
|
- Lee Jarvis
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
date: 2011-07-01 00:00:00.000000000 +01:00
|
|
14
|
+
default_executable:
|
|
15
15
|
dependencies: []
|
|
16
|
-
|
|
17
16
|
description: Chronic is a natural language date/time parser written in pure Ruby.
|
|
18
|
-
email:
|
|
17
|
+
email:
|
|
19
18
|
- tom@mojombo.com
|
|
20
19
|
- lee@jarvis.co
|
|
21
20
|
executables: []
|
|
22
|
-
|
|
23
21
|
extensions: []
|
|
24
|
-
|
|
25
|
-
extra_rdoc_files:
|
|
22
|
+
extra_rdoc_files:
|
|
26
23
|
- README.md
|
|
27
24
|
- HISTORY.md
|
|
28
25
|
- LICENSE
|
|
29
|
-
files:
|
|
26
|
+
files:
|
|
27
|
+
- .gemtest
|
|
28
|
+
- .gitignore
|
|
29
|
+
- .yardopts
|
|
30
30
|
- HISTORY.md
|
|
31
31
|
- LICENSE
|
|
32
32
|
- Manifest.txt
|
|
33
33
|
- README.md
|
|
34
34
|
- Rakefile
|
|
35
|
-
- benchmark/benchmark.rb
|
|
36
35
|
- chronic.gemspec
|
|
37
36
|
- lib/chronic.rb
|
|
38
37
|
- lib/chronic/chronic.rb
|
|
@@ -60,6 +59,7 @@ files:
|
|
|
60
59
|
- lib/chronic/repeaters/repeater_weekend.rb
|
|
61
60
|
- lib/chronic/repeaters/repeater_year.rb
|
|
62
61
|
- lib/chronic/scalar.rb
|
|
62
|
+
- lib/chronic/season.rb
|
|
63
63
|
- lib/chronic/separator.rb
|
|
64
64
|
- lib/chronic/span.rb
|
|
65
65
|
- lib/chronic/tag.rb
|
|
@@ -77,6 +77,7 @@ files:
|
|
|
77
77
|
- test/test_RepeaterMinute.rb
|
|
78
78
|
- test/test_RepeaterMonth.rb
|
|
79
79
|
- test/test_RepeaterMonthName.rb
|
|
80
|
+
- test/test_RepeaterSeason.rb
|
|
80
81
|
- test/test_RepeaterTime.rb
|
|
81
82
|
- test/test_RepeaterWeek.rb
|
|
82
83
|
- test/test_RepeaterWeekday.rb
|
|
@@ -86,34 +87,34 @@ files:
|
|
|
86
87
|
- test/test_Time.rb
|
|
87
88
|
- test/test_Token.rb
|
|
88
89
|
- test/test_parsing.rb
|
|
90
|
+
has_rdoc: true
|
|
89
91
|
homepage: http://github.com/mojombo/chronic
|
|
90
92
|
licenses: []
|
|
91
|
-
|
|
92
93
|
post_install_message:
|
|
93
|
-
rdoc_options:
|
|
94
|
+
rdoc_options:
|
|
94
95
|
- --charset=UTF-8
|
|
95
|
-
require_paths:
|
|
96
|
+
require_paths:
|
|
96
97
|
- lib
|
|
97
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
99
|
none: false
|
|
99
|
-
requirements:
|
|
100
|
-
- -
|
|
101
|
-
- !ruby/object:Gem::Version
|
|
102
|
-
version:
|
|
103
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ! '>='
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
105
|
none: false
|
|
105
|
-
requirements:
|
|
106
|
-
- -
|
|
107
|
-
- !ruby/object:Gem::Version
|
|
108
|
-
version:
|
|
106
|
+
requirements:
|
|
107
|
+
- - ! '>='
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
109
110
|
requirements: []
|
|
110
|
-
|
|
111
111
|
rubyforge_project: chronic
|
|
112
|
-
rubygems_version: 1.
|
|
112
|
+
rubygems_version: 1.6.2
|
|
113
113
|
signing_key:
|
|
114
114
|
specification_version: 3
|
|
115
115
|
summary: Natural language date/time parsing.
|
|
116
|
-
test_files:
|
|
116
|
+
test_files:
|
|
117
|
+
- test/helper.rb
|
|
117
118
|
- test/test_Chronic.rb
|
|
118
119
|
- test/test_DaylightSavings.rb
|
|
119
120
|
- test/test_Handler.rb
|
|
@@ -125,6 +126,7 @@ test_files:
|
|
|
125
126
|
- test/test_RepeaterMinute.rb
|
|
126
127
|
- test/test_RepeaterMonth.rb
|
|
127
128
|
- test/test_RepeaterMonthName.rb
|
|
129
|
+
- test/test_RepeaterSeason.rb
|
|
128
130
|
- test/test_RepeaterTime.rb
|
|
129
131
|
- test/test_RepeaterWeek.rb
|
|
130
132
|
- test/test_RepeaterWeekday.rb
|
data/benchmark/benchmark.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require 'chronic'
|
|
2
|
-
require 'benchmark'
|
|
3
|
-
|
|
4
|
-
print "jan 3 2010: "
|
|
5
|
-
puts Benchmark.measure { Chronic.parse("jan 3 2010") }
|
|
6
|
-
|
|
7
|
-
print "7 hours before tomorrow at midnight: "
|
|
8
|
-
puts Benchmark.measure { Chronic.parse("7 hours before tomorrow at midnight") }
|
|
9
|
-
|
|
10
|
-
# n = 100
|
|
11
|
-
# Benchmark.bm(14) do |x|
|
|
12
|
-
# x.report("jan 3 2010:") { for i in 1..n; Chronic.parse("jan 3 2010"); end }
|
|
13
|
-
# end
|