chronic 0.6.3 → 0.6.4
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 +7 -0
- data/Rakefile +3 -5
- data/lib/chronic.rb +1 -1
- data/lib/chronic/chronic.rb +3 -1
- data/lib/chronic/handlers.rb +31 -1
- data/lib/chronic/repeaters/repeater_day_portion.rb +4 -4
- data/lib/chronic/repeaters/repeater_time.rb +19 -19
- data/lib/chronic/repeaters/repeater_year.rb +1 -1
- data/test/helper.rb +1 -1
- data/test/test_parsing.rb +25 -4
- metadata +21 -38
data/HISTORY.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 0.6.4 / 2011-08-08
|
2
|
+
|
3
|
+
* Fixed bug where 'noon' was parsed as 00:00 rather than 12:00
|
4
|
+
with :ambiguous_time_range => :none (Vladimir Chernis)
|
5
|
+
* Add support for handling '2009 May 22nd'
|
6
|
+
* Add the ability to handle scalar-day/repeater-month-name as well as ordinals
|
7
|
+
|
1
8
|
# 0.6.3 / 2011-08-01
|
2
9
|
|
3
10
|
* Ensure 'thu' is parsed as Thursday for 1.8.7 generic timestamp
|
data/Rakefile
CHANGED
@@ -5,11 +5,9 @@ def version
|
|
5
5
|
contents[/VERSION = "([^"]+)"/, 1]
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
test.
|
11
|
-
test.pattern = 'test/**/test_*.rb'
|
12
|
-
test.verbose = true
|
8
|
+
task :test do
|
9
|
+
$:.unshift './test'
|
10
|
+
Dir.glob('test/test_*.rb').each { |t| require File.basename(t) }
|
13
11
|
end
|
14
12
|
|
15
13
|
desc "Generate RCov test coverage and open in your browser"
|
data/lib/chronic.rb
CHANGED
data/lib/chronic/chronic.rb
CHANGED
@@ -118,7 +118,7 @@ module Chronic
|
|
118
118
|
text.gsub!(/\btoday\b/, 'this day')
|
119
119
|
text.gsub!(/\btomm?orr?ow\b/, 'next day')
|
120
120
|
text.gsub!(/\byesterday\b/, 'last day')
|
121
|
-
text.gsub!(/\bnoon\b/, '12:
|
121
|
+
text.gsub!(/\bnoon\b/, '12:00pm')
|
122
122
|
text.gsub!(/\bmidnight\b/, '24:00')
|
123
123
|
text.gsub!(/\bnow\b/, 'this second')
|
124
124
|
text.gsub!(/\b(?:ago|before(?: now)?)\b/, 'past')
|
@@ -179,9 +179,11 @@ module Chronic
|
|
179
179
|
Handler.new([:repeater_month_name, :ordinal_day, :separator_at?, 'time?'], :handle_rmn_od),
|
180
180
|
Handler.new([:ordinal_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_od_rmn_sy),
|
181
181
|
Handler.new([:ordinal_day, :repeater_month_name, :separator_at?, 'time?'], :handle_od_rmn),
|
182
|
+
Handler.new([:scalar_year, :repeater_month_name, :ordinal_day], :handle_sy_rmn_od),
|
182
183
|
Handler.new([:repeater_time, :repeater_day_portion?, :separator_on?, :repeater_month_name, :ordinal_day], :handle_rmn_od_on),
|
183
184
|
Handler.new([:repeater_month_name, :scalar_year], :handle_rmn_sy),
|
184
185
|
Handler.new([:scalar_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_sd_rmn_sy),
|
186
|
+
Handler.new([:scalar_day, :repeater_month_name, :separator_at?, 'time?'], :handle_sd_rmn),
|
185
187
|
Handler.new([:scalar_year, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_day, :separator_at?, 'time?'], :handle_sy_sm_sd),
|
186
188
|
Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_year], :handle_sm_sy)
|
187
189
|
],
|
data/lib/chronic/handlers.rb
CHANGED
@@ -59,6 +59,32 @@ module Chronic
|
|
59
59
|
handle_m_d(month, day, tokens[2..tokens.size], options)
|
60
60
|
end
|
61
61
|
|
62
|
+
def handle_sy_rmn_od(tokens, options)
|
63
|
+
year = tokens[0].get_tag(ScalarYear).type
|
64
|
+
month = tokens[1].get_tag(RepeaterMonthName).index
|
65
|
+
day = tokens[2].get_tag(OrdinalDay).type
|
66
|
+
time_tokens = tokens.last(tokens.size - 3)
|
67
|
+
|
68
|
+
return if month_overflow?(year, month, day)
|
69
|
+
|
70
|
+
begin
|
71
|
+
day_start = Chronic.time_class.local(year, month, day)
|
72
|
+
day_or_time(day_start, time_tokens, options)
|
73
|
+
rescue ArgumentError
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Handle scalar-day/repeater-month-name
|
79
|
+
def handle_sd_rmn(tokens, options)
|
80
|
+
month = tokens[1].get_tag(RepeaterMonthName)
|
81
|
+
day = tokens[0].get_tag(ScalarDay).type
|
82
|
+
|
83
|
+
return if month_overflow?(Chronic.now.year, month.index, day)
|
84
|
+
|
85
|
+
handle_m_d(month, day, tokens[2..tokens.size], options)
|
86
|
+
end
|
87
|
+
|
62
88
|
# Handle repeater-month-name/ordinal-day with separator-on
|
63
89
|
def handle_rmn_od_on(tokens, options)
|
64
90
|
if tokens.size > 3
|
@@ -339,7 +365,11 @@ module Chronic
|
|
339
365
|
raise ChronicPain, "Invalid grabber"
|
340
366
|
end
|
341
367
|
|
342
|
-
|
368
|
+
if Chronic.debug
|
369
|
+
puts "Handler-class: #{head.class}"
|
370
|
+
puts "--#{outer_span}"
|
371
|
+
end
|
372
|
+
|
343
373
|
find_within(repeaters, outer_span, pointer)
|
344
374
|
end
|
345
375
|
|
@@ -3,10 +3,10 @@ module Chronic
|
|
3
3
|
PORTIONS = {
|
4
4
|
:am => 0..(12 * 60 * 60 - 1),
|
5
5
|
:pm => (12 * 60 * 60)..(24 * 60 * 60 - 1),
|
6
|
-
:morning => (6 * 60 * 60)..(12 * 60 * 60),
|
7
|
-
:afternoon =>(13 * 60 * 60)..(17 * 60 * 60), # 1pm-5pm,
|
8
|
-
:evening => (17 * 60 * 60)..(20 * 60 * 60),
|
9
|
-
:night =>(20 * 60 * 60)..(24 * 60 * 60), # 8pm-12pm
|
6
|
+
:morning => (6 * 60 * 60)..(12 * 60 * 60), # 6am-12am,
|
7
|
+
:afternoon => (13 * 60 * 60)..(17 * 60 * 60), # 1pm-5pm,
|
8
|
+
:evening => (17 * 60 * 60)..(20 * 60 * 60), # 5pm-8pm,
|
9
|
+
:night => (20 * 60 * 60)..(24 * 60 * 60), # 8pm-12pm
|
10
10
|
}
|
11
11
|
|
12
12
|
def initialize(type)
|
@@ -31,25 +31,25 @@ module Chronic
|
|
31
31
|
|
32
32
|
@type =
|
33
33
|
case t.size
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
34
|
+
when 1..2
|
35
|
+
hours = t.to_i
|
36
|
+
Tick.new((hours == 12 ? 0 : hours) * 60 * 60, true)
|
37
|
+
when 3
|
38
|
+
hours = t[0..0].to_i
|
39
|
+
ambiguous = hours > 0
|
40
|
+
Tick.new((hours * 60 * 60) + (t[1..2].to_i * 60), ambiguous)
|
41
|
+
when 4
|
42
|
+
ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
|
43
|
+
hours = t[0..1].to_i
|
44
|
+
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)
|
45
|
+
when 5
|
46
|
+
Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
|
47
|
+
when 6
|
48
|
+
ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
|
49
|
+
hours = t[0..1].to_i
|
50
|
+
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)
|
51
|
+
else
|
52
|
+
raise("Time cannot exceed six digits")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -29,7 +29,7 @@ module Chronic
|
|
29
29
|
|
30
30
|
case pointer
|
31
31
|
when :future
|
32
|
-
this_year_start = Chronic.construct(@now.year, @now.month, @now.day
|
32
|
+
this_year_start = Chronic.construct(@now.year, @now.month, @now.day + 1)
|
33
33
|
this_year_end = Chronic.construct(@now.year + 1, 1, 1)
|
34
34
|
when :past
|
35
35
|
this_year_start = Chronic.construct(@now.year, 1, 1)
|
data/test/helper.rb
CHANGED
data/test/test_parsing.rb
CHANGED
@@ -76,6 +76,22 @@ class TestParsing < Test::Unit::TestCase
|
|
76
76
|
assert_equal Time.local(2006, 12, 11, 8), time
|
77
77
|
end
|
78
78
|
|
79
|
+
def test_handle_sy_rmn_od
|
80
|
+
time = parse_now("2009 May 22nd")
|
81
|
+
assert_equal Time.local(2009, 05, 22, 12), time
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_handle_sd_rmn
|
85
|
+
time = parse_now("22 February")
|
86
|
+
assert_equal Time.local(2007, 2, 22, 12), time
|
87
|
+
|
88
|
+
time = parse_now("31 of may at 6:30pm")
|
89
|
+
assert_equal Time.local(2007, 5, 31, 18, 30), time
|
90
|
+
|
91
|
+
time = parse_now("11 december 8am")
|
92
|
+
assert_equal Time.local(2006, 12, 11, 8), time
|
93
|
+
end
|
94
|
+
|
79
95
|
def test_handle_rmn_od_on
|
80
96
|
time = parse_now("5:00 pm may 27th", :context => :past)
|
81
97
|
assert_equal Time.local(2006, 5, 27, 17), time
|
@@ -417,11 +433,11 @@ class TestParsing < Test::Unit::TestCase
|
|
417
433
|
def test_parse_guess_gr
|
418
434
|
# year
|
419
435
|
|
420
|
-
time = parse_now("this year")
|
421
|
-
assert_equal Time.local(2006,
|
436
|
+
time = parse_now("this year", :guess => false)
|
437
|
+
assert_equal Time.local(2006, 8, 17), time.begin
|
422
438
|
|
423
|
-
time = parse_now("this year", :context => :past)
|
424
|
-
assert_equal Time.local(2006,
|
439
|
+
time = parse_now("this year", :context => :past, :guess => false)
|
440
|
+
assert_equal Time.local(2006, 1, 1), time.begin
|
425
441
|
|
426
442
|
# month
|
427
443
|
|
@@ -858,6 +874,11 @@ class TestParsing < Test::Unit::TestCase
|
|
858
874
|
assert_not_equal t1, t2
|
859
875
|
end
|
860
876
|
|
877
|
+
def test_noon
|
878
|
+
t1 = Chronic.parse('2011-01-01 at noon', :ambiguous_time_range => :none)
|
879
|
+
assert_equal Time.local(2011, 1, 1, 12, 0), t1
|
880
|
+
end
|
881
|
+
|
861
882
|
private
|
862
883
|
def parse_now(string, options={})
|
863
884
|
Chronic.parse(string, {:now => TIME_2006_08_16_14_00_00 }.merge(options))
|
metadata
CHANGED
@@ -1,37 +1,28 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronic
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.4
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 3
|
10
|
-
version: 0.6.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Tom Preston-Werner
|
14
9
|
- Lee Jarvis
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
date: 2011-09-02 00:00:00 Z
|
13
|
+
date: 2011-09-09 00:00:00.000000000Z
|
20
14
|
dependencies: []
|
21
|
-
|
22
15
|
description: Chronic is a natural language date/time parser written in pure Ruby.
|
23
|
-
email:
|
16
|
+
email:
|
24
17
|
- tom@mojombo.com
|
25
18
|
- lee@jarvis.co
|
26
19
|
executables: []
|
27
|
-
|
28
20
|
extensions: []
|
29
|
-
|
30
|
-
extra_rdoc_files:
|
21
|
+
extra_rdoc_files:
|
31
22
|
- README.md
|
32
23
|
- HISTORY.md
|
33
24
|
- LICENSE
|
34
|
-
files:
|
25
|
+
files:
|
35
26
|
- .gemtest
|
36
27
|
- .gitignore
|
37
28
|
- .yardopts
|
@@ -96,38 +87,30 @@ files:
|
|
96
87
|
- test/test_parsing.rb
|
97
88
|
homepage: http://github.com/mojombo/chronic
|
98
89
|
licenses: []
|
99
|
-
|
100
90
|
post_install_message:
|
101
|
-
rdoc_options:
|
91
|
+
rdoc_options:
|
102
92
|
- --charset=UTF-8
|
103
|
-
require_paths:
|
93
|
+
require_paths:
|
104
94
|
- lib
|
105
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
96
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
|
111
|
-
|
112
|
-
- 0
|
113
|
-
version: "0"
|
114
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
102
|
none: false
|
116
|
-
requirements:
|
117
|
-
- -
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
|
120
|
-
segments:
|
121
|
-
- 0
|
122
|
-
version: "0"
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
123
107
|
requirements: []
|
124
|
-
|
125
108
|
rubyforge_project: chronic
|
126
109
|
rubygems_version: 1.8.6
|
127
110
|
signing_key:
|
128
111
|
specification_version: 3
|
129
112
|
summary: Natural language date/time parsing.
|
130
|
-
test_files:
|
113
|
+
test_files:
|
131
114
|
- test/helper.rb
|
132
115
|
- test/test_Chronic.rb
|
133
116
|
- test/test_DaylightSavings.rb
|