chronic 0.2.2 → 0.2.3
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.txt +5 -1
- data/lib/chronic.rb +1 -1
- data/lib/chronic/repeaters/repeater_day_portion.rb +2 -2
- data/lib/chronic/repeaters/repeater_time.rb +10 -7
- data/test/test_parsing.rb +22 -0
- metadata +10 -7
data/History.txt
CHANGED
data/lib/chronic.rb
CHANGED
@@ -10,8 +10,8 @@ class Chronic::RepeaterDayPortion < Chronic::Repeater #:nodoc:
|
|
10
10
|
if type.kind_of? Integer
|
11
11
|
@range = (@type * 60 * 60)..((@type + 12) * 60 * 60)
|
12
12
|
else
|
13
|
-
lookup = {:am =>
|
14
|
-
:pm => (12 * 60 * 60)..(24 * 60 * 60),
|
13
|
+
lookup = {:am => 0..(12 * 60 * 60 - 1),
|
14
|
+
:pm => (12 * 60 * 60)..(24 * 60 * 60 - 1),
|
15
15
|
:morning => @@morning,
|
16
16
|
:afternoon => @@afternoon,
|
17
17
|
:evening => @@evening,
|
@@ -28,17 +28,20 @@ class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
|
|
28
28
|
t = time.gsub(/\:/, '')
|
29
29
|
@type =
|
30
30
|
if (1..2) === t.size
|
31
|
-
|
31
|
+
hours = t.to_i
|
32
|
+
hours == 12 ? Tick.new(0 * 60 * 60, true) : Tick.new(hours * 60 * 60, true)
|
32
33
|
elsif t.size == 3
|
33
34
|
Tick.new((t[0..0].to_i * 60 * 60) + (t[1..2].to_i * 60), true)
|
34
35
|
elsif t.size == 4
|
35
36
|
ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
|
36
|
-
|
37
|
+
hours = t[0..1].to_i
|
38
|
+
hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60, ambiguous)
|
37
39
|
elsif t.size == 5
|
38
40
|
Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
|
39
41
|
elsif t.size == 6
|
40
42
|
ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
|
41
|
-
|
43
|
+
hours = t[0..1].to_i
|
44
|
+
hours == 12 ? Tick.new(0 * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous) : Tick.new(hours * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
|
42
45
|
else
|
43
46
|
raise("Time cannot exceed six digits")
|
44
47
|
end
|
@@ -65,21 +68,21 @@ class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
|
|
65
68
|
if pointer == :future
|
66
69
|
if @type.ambiguous?
|
67
70
|
[midnight + @type, midnight + half_day + @type, tomorrow_midnight + @type].each do |t|
|
68
|
-
(@current_time = t; throw :done) if t
|
71
|
+
(@current_time = t; throw :done) if t >= @now
|
69
72
|
end
|
70
73
|
else
|
71
74
|
[midnight + @type, tomorrow_midnight + @type].each do |t|
|
72
|
-
(@current_time = t; throw :done) if t
|
75
|
+
(@current_time = t; throw :done) if t >= @now
|
73
76
|
end
|
74
77
|
end
|
75
78
|
else # pointer == :past
|
76
79
|
if @type.ambiguous?
|
77
80
|
[midnight + half_day + @type, midnight + @type, yesterday_midnight + @type * 2].each do |t|
|
78
|
-
(@current_time = t; throw :done) if t
|
81
|
+
(@current_time = t; throw :done) if t <= @now
|
79
82
|
end
|
80
83
|
else
|
81
84
|
[midnight + @type, yesterday_midnight + @type].each do |t|
|
82
|
-
(@current_time = t; throw :done) if t
|
85
|
+
(@current_time = t; throw :done) if t <= @now
|
83
86
|
end
|
84
87
|
end
|
85
88
|
end
|
data/test/test_parsing.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'chronic'
|
2
|
+
require 'time'
|
2
3
|
require 'test/unit'
|
3
4
|
|
4
5
|
class TestParsing < Test::Unit::TestCase
|
@@ -208,6 +209,18 @@ class TestParsing < Test::Unit::TestCase
|
|
208
209
|
time = parse_now("4 am", :ambiguous_time_range => :none)
|
209
210
|
assert_equal Time.local(2006, 8, 16, 4), time
|
210
211
|
|
212
|
+
time = parse_now("12 pm")
|
213
|
+
assert_equal Time.local(2006, 8, 16, 12), time
|
214
|
+
|
215
|
+
time = parse_now("12:01 pm")
|
216
|
+
assert_equal Time.local(2006, 8, 16, 12, 1), time
|
217
|
+
|
218
|
+
time = parse_now("12:01 am")
|
219
|
+
assert_equal Time.local(2006, 8, 16, 0, 1), time
|
220
|
+
|
221
|
+
time = parse_now("12 am")
|
222
|
+
assert_equal Time.local(2006, 8, 16), time
|
223
|
+
|
211
224
|
time = parse_now("4:00 in the morning")
|
212
225
|
assert_equal Time.local(2006, 8, 16, 4), time
|
213
226
|
|
@@ -411,6 +424,12 @@ class TestParsing < Test::Unit::TestCase
|
|
411
424
|
|
412
425
|
time = parse_now("tomorrow morning at 5:30")
|
413
426
|
assert_equal Time.local(2006, 8, 17, 5, 30), time
|
427
|
+
|
428
|
+
time = parse_now("next monday at 12:01 am")
|
429
|
+
assert_equal Time.local(2006, 8, 21, 00, 1), time
|
430
|
+
|
431
|
+
time = parse_now("next monday at 12:01 pm")
|
432
|
+
assert_equal Time.local(2006, 8, 21, 12, 1), time
|
414
433
|
end
|
415
434
|
|
416
435
|
def test_parse_guess_rgr
|
@@ -531,6 +550,9 @@ class TestParsing < Test::Unit::TestCase
|
|
531
550
|
|
532
551
|
time = parse_now("10th wednesday in november")
|
533
552
|
assert_equal nil, time
|
553
|
+
|
554
|
+
# time = parse_now("3rd wednesday in 2007")
|
555
|
+
# assert_equal Time.local(2007, 1, 20, 12), time
|
534
556
|
end
|
535
557
|
|
536
558
|
def test_parse_guess_o_r_g_r
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: chronic
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.2.3
|
7
|
+
date: 2007-07-02 00:00:00 -07:00
|
8
8
|
summary: A natural language date parser
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -93,10 +93,13 @@ test_files:
|
|
93
93
|
- test/test_Span.rb
|
94
94
|
- test/test_Time.rb
|
95
95
|
- test/test_Token.rb
|
96
|
-
rdoc_options:
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
rdoc_options:
|
97
|
+
- --main
|
98
|
+
- README.txt
|
99
|
+
extra_rdoc_files:
|
100
|
+
- History.txt
|
101
|
+
- Manifest.txt
|
102
|
+
- README.txt
|
100
103
|
executables: []
|
101
104
|
|
102
105
|
extensions: []
|
@@ -111,5 +114,5 @@ dependencies:
|
|
111
114
|
requirements:
|
112
115
|
- - ">="
|
113
116
|
- !ruby/object:Gem::Version
|
114
|
-
version: 1.2.
|
117
|
+
version: 1.2.1
|
115
118
|
version:
|