chronic 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ = 0.2.0 2007-03-20
2
+
3
+ * fixed time overflow issue
4
+ * implemented numerizer, allowing the use of number words (e.g. five weeks ago) (shalev)
5
+
1
6
  = 0.1.6 2006-01-15
2
7
 
3
8
  * added 'weekend' support (eventualbuddha)
@@ -26,10 +26,11 @@ lib/chronic/repeaters/repeater_weekend.rb
26
26
  lib/chronic/repeaters/repeater_year.rb
27
27
  lib/chronic/scalar.rb
28
28
  lib/chronic/separator.rb
29
- test/parse_numbers.rb
29
+ lib/numerizer/numerizer.rb
30
30
  test/suite.rb
31
31
  test/test_Chronic.rb
32
32
  test/test_Handler.rb
33
+ test/test_Numerizer.rb
33
34
  test/test_RepeaterDayName.rb
34
35
  test/test_RepeaterFortnight.rb
35
36
  test/test_RepeaterHour.rb
@@ -37,6 +38,7 @@ test/test_RepeaterMonth.rb
37
38
  test/test_RepeaterMonthName.rb
38
39
  test/test_RepeaterTime.rb
39
40
  test/test_RepeaterWeek.rb
41
+ test/test_RepeaterWeekend.rb
40
42
  test/test_RepeaterYear.rb
41
43
  test/test_Span.rb
42
44
  test/test_Token.rb
@@ -7,6 +7,8 @@
7
7
  #
8
8
  #=============================================================================
9
9
 
10
+ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
11
+
10
12
  require 'chronic/chronic'
11
13
  require 'chronic/handlers'
12
14
 
@@ -33,8 +35,10 @@ require 'chronic/scalar'
33
35
  require 'chronic/ordinal'
34
36
  require 'chronic/separator'
35
37
 
38
+ require 'numerizer/numerizer'
39
+
36
40
  module Chronic
37
- VERSION = "0.1.6"
41
+ VERSION = "0.2.0"
38
42
 
39
43
  def self.debug; false; end
40
44
  end
@@ -44,4 +48,25 @@ alias p_orig p
44
48
  def p(val)
45
49
  p_orig val
46
50
  puts
51
+ end
52
+
53
+ class Time
54
+ def self.construct(year, month = 1, day = 1, hour = 0, minute = 0, second = 0)
55
+ if second >= 60
56
+ minute += second / 60
57
+ second = second % 60
58
+ end
59
+
60
+ if minute >= 60
61
+ hour += minute / 60
62
+ minute = minute % 60
63
+ end
64
+
65
+ if hour >= 24
66
+ day += hour / 24
67
+ hour = hour % 24
68
+ end
69
+
70
+ Time.local(year, month, day, hour, minute, second)
71
+ end
47
72
  end
@@ -101,6 +101,7 @@ module Chronic
101
101
  # ordinals (third => 3rd)
102
102
  def pre_normalize(text) #:nodoc:
103
103
  normalized_text = text.to_s.downcase
104
+ normalized_text = numericize_numbers(normalized_text)
104
105
  normalized_text.gsub!(/['"\.]/, '')
105
106
  normalized_text.gsub!(/([\/\-\,\@])/) { ' ' + $1 + ' ' }
106
107
  normalized_text.gsub!(/\btoday\b/, 'this day')
@@ -118,15 +119,12 @@ module Chronic
118
119
  normalized_text.gsub!(/\btonight\b/, 'this night')
119
120
  normalized_text.gsub!(/(?=\w)([ap]m|oclock)\b/, ' \1')
120
121
  normalized_text.gsub!(/\b(hence|after|from)\b/, 'future')
121
- normalized_text.gsub!(/\ba\b/, '1')
122
- normalized_text.gsub!(/\s+/, ' ')
123
- normalized_text = numericize_numbers(normalized_text)
124
122
  normalized_text = numericize_ordinals(normalized_text)
125
123
  end
126
124
 
127
125
  # Convert number words to numbers (three => 3)
128
126
  def numericize_numbers(text) #:nodoc:
129
- text
127
+ Numerizer.numerize(text)
130
128
  end
131
129
 
132
130
  # Convert ordinal words to numeric ordinals (third => 3rd)
@@ -214,17 +214,19 @@ module Chronic
214
214
  def handle_s_r_p(tokens, options) #:nodoc:
215
215
  repeater = tokens[1].get_tag(Repeater)
216
216
 
217
- span =
218
- case true
219
- when [RepeaterYear, RepeaterSeason, RepeaterSeasonName, RepeaterMonth, RepeaterMonthName, RepeaterFortnight, RepeaterWeek].include?(repeater.class)
220
- self.parse("this hour", :guess => false, :now => @now)
221
- when [RepeaterWeekend, RepeaterDay, RepeaterDayName, RepeaterDayPortion, RepeaterHour].include?(repeater.class)
222
- self.parse("this minute", :guess => false, :now => @now)
223
- when [RepeaterMinute, RepeaterSecond].include?(repeater.class)
224
- self.parse("this second", :guess => false, :now => @now)
225
- else
226
- raise(ChronicPain, "Invalid repeater: #{repeater.class}")
227
- end
217
+ # span =
218
+ # case true
219
+ # when [RepeaterYear, RepeaterSeason, RepeaterSeasonName, RepeaterMonth, RepeaterMonthName, RepeaterFortnight, RepeaterWeek].include?(repeater.class)
220
+ # self.parse("this hour", :guess => false, :now => @now)
221
+ # when [RepeaterWeekend, RepeaterDay, RepeaterDayName, RepeaterDayPortion, RepeaterHour].include?(repeater.class)
222
+ # self.parse("this minute", :guess => false, :now => @now)
223
+ # when [RepeaterMinute, RepeaterSecond].include?(repeater.class)
224
+ # self.parse("this second", :guess => false, :now => @now)
225
+ # else
226
+ # raise(ChronicPain, "Invalid repeater: #{repeater.class}")
227
+ # end
228
+
229
+ span = self.parse("this second", :guess => false, :now => @now)
228
230
 
229
231
  self.handle_srp(tokens, span, options)
230
232
  end
@@ -10,9 +10,9 @@ module Chronic
10
10
  end
11
11
 
12
12
  def self.scan_for_all(token)
13
- scanner = {/past/ => :past,
14
- /future/ => :future,
15
- /in/ => :future}
13
+ scanner = {/\bpast\b/ => :past,
14
+ /\bfuture\b/ => :future,
15
+ /\bin\b/ => :future}
16
16
  scanner.keys.each do |scanner_item|
17
17
  return self.new(scanner[scanner_item]) if scanner_item =~ token.word
18
18
  end
@@ -24,8 +24,8 @@ class Chronic::RepeaterHour < Chronic::Repeater #:nodoc:
24
24
 
25
25
  case pointer
26
26
  when :future
27
- hour_start = Time.local(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
28
- hour_end = Time.local(@now.year, @now.month, @now.day, @now.hour + 1)
27
+ hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
28
+ hour_end = Time.construct(@now.year, @now.month, @now.day, @now.hour + 1)
29
29
  when :past
30
30
  hour_start = Time.local(@now.year, @now.month, @now.day, @now.hour)
31
31
  hour_end = Time.local(@now.year, @now.month, @now.day, @now.hour, @now.min)
@@ -0,0 +1,103 @@
1
+ require 'strscan'
2
+
3
+ class Numerizer
4
+
5
+ DIRECT_NUMS = [
6
+ ['eleven', '11'],
7
+ ['twelve', '12'],
8
+ ['thirteen', '13'],
9
+ ['fourteen', '14'],
10
+ ['fifteen', '15'],
11
+ ['sixteen', '16'],
12
+ ['seventeen', '17'],
13
+ ['eighteen', '18'],
14
+ ['nineteen', '19'],
15
+ ['ninteen', '19'], # Common mis-spelling
16
+ ['zero', '0'],
17
+ ['one', '1'],
18
+ ['two', '2'],
19
+ ['three', '3'],
20
+ ['four(\W|$)', '4\1'], # The weird regex is so that it matches four but not fourty
21
+ ['five', '5'],
22
+ ['six(\W|$)', '6\1'],
23
+ ['seven(\W|$)', '7\1'],
24
+ ['eight(\W|$)', '8\1'],
25
+ ['nine(\W|$)', '9\1'],
26
+ ['ten', '10'],
27
+ ['\ba[\b^$]', '1'] # doesn't make sense for an 'a' at the end to be a 1
28
+ ]
29
+
30
+ TEN_PREFIXES = [ ['twenty', 20],
31
+ ['thirty', 30],
32
+ ['fourty', 40],
33
+ ['fifty', 50],
34
+ ['sixty', 60],
35
+ ['seventy', 70],
36
+ ['eighty', 80],
37
+ ['ninety', 90]
38
+ ]
39
+
40
+ BIG_PREFIXES = [ ['hundred', 100],
41
+ ['thousand', 1000],
42
+ ['million', 1_000_000],
43
+ ['billion', 1_000_000_000],
44
+ ['trillion', 1_000_000_000_000],
45
+ ]
46
+
47
+ class << self
48
+ def numerize(string)
49
+ string = string.dup
50
+
51
+ # preprocess
52
+ string.gsub!(/ +|([^\d])-([^d])/, '\1 \2') # will mutilate hyphenated-words but shouldn't matter for date extraction
53
+ string.gsub!(/a half/, 'haAlf') # take the 'a' out so it doesn't turn into a 1, save the half for the end
54
+
55
+ # easy/direct replacements
56
+
57
+ DIRECT_NUMS.each do |dn|
58
+ string.gsub!(/#{dn[0]}/i, dn[1])
59
+ end
60
+
61
+ # ten, twenty, etc.
62
+
63
+ TEN_PREFIXES.each do |tp|
64
+ string.gsub!(/(?:#{tp[0]})( *\d(?=[^\d]|$))*/i) { (tp[1] + $1.to_i).to_s }
65
+ end
66
+
67
+ # hundreds, thousands, millions, etc.
68
+
69
+ BIG_PREFIXES.each do |bp|
70
+ string.gsub!(/(\d*) *#{bp[0]}/i) { (bp[1] * $1.to_i).to_s}
71
+ andition(string)
72
+ #combine_numbers(string) # Should to be more efficient way to do this
73
+ end
74
+
75
+ # fractional addition
76
+ # I'm not combining this with the previous block as using float addition complicates the strings
77
+ # (with extraneous .0's and such )
78
+ string.gsub!(/(\d+)(?: | and |-)*haAlf/i) { ($1.to_f + 0.5).to_s }
79
+
80
+ string
81
+ end
82
+
83
+ private
84
+ def andition(string)
85
+ sc = StringScanner.new(string)
86
+ while(sc.scan_until(/(\d+)( | and )(\d+)(?=[^\w]|$)/i))
87
+ if sc[2] =~ /and/ || sc[1].size > sc[3].size
88
+ string[(sc.pos - sc.matched_size)..(sc.pos-1)] = (sc[1].to_i + sc[3].to_i).to_s
89
+ sc.reset
90
+ end
91
+ end
92
+ end
93
+
94
+ # def combine_numbers(string)
95
+ # sc = StringScanner.new(string)
96
+ # while(sc.scan_until(/(\d+)(?: | and |-)(\d+)(?=[^\w]|$)/i))
97
+ # string[(sc.pos - sc.matched_size)..(sc.pos-1)] = (sc[1].to_i + sc[2].to_i).to_s
98
+ # sc.reset
99
+ # end
100
+ # end
101
+
102
+ end
103
+ end
@@ -1,11 +1,10 @@
1
- __END__
2
-
3
1
  require 'test/unit'
2
+ require 'chronic'
4
3
 
5
4
  class ParseNumbersTest < Test::Unit::TestCase
6
5
 
7
- def test_parse
8
- strings = {1 => 'one',
6
+ def test_straight_parsing
7
+ strings = { 1 => 'one',
9
8
  5 => 'five',
10
9
  10 => 'ten',
11
10
  11 => 'eleven',
@@ -24,7 +23,7 @@ class ParseNumbersTest < Test::Unit::TestCase
24
23
  100 => 'a hundred',
25
24
  100 => 'one hundred',
26
25
  150 => 'one hundred and fifty',
27
- 150 => 'one fifty',
26
+ # 150 => 'one fifty',
28
27
  200 => 'two-hundred',
29
28
  500 => '5 hundred',
30
29
  999 => 'nine hundred and ninety nine',
@@ -40,11 +39,10 @@ class ParseNumbersTest < Test::Unit::TestCase
40
39
  1_000_000 => 'one million',
41
40
  1_250_007 => 'one million two hundred fifty thousand and seven',
42
41
  1_000_000_000 => 'one billion',
43
- 1_000_000_001 => 'one billion and one'}
42
+ 1_000_000_001 => 'one billion and one' }
44
43
 
45
44
  strings.keys.sort.each do |key|
46
- assert_equal key, JW::NumberMagick.convert(strings[key])
45
+ assert_equal key, Numerizer.numerize(strings[key]).to_i
47
46
  end
48
47
  end
49
-
50
48
  end
@@ -2,514 +2,517 @@ require 'chronic'
2
2
  require 'test/unit'
3
3
 
4
4
  class TestParsing < Test::Unit::TestCase
5
+ # Wed Aug 16 14:00:00 UTC 2006
6
+ TIME_2006_08_16_14_00_00 = Time.local(2006, 8, 16, 14, 0, 0, 0)
5
7
 
6
8
  def setup
7
- # Wed Aug 16 14:00:00 UTC 2006
8
- @time_2006_08_16_14_00_00 = Time.local(2006, 8, 16, 14, 0, 0, 0)
9
- @time_2006_08_16_03_00_00 = Time.local(2006, 8, 16, 3, 0, 0, 0)
9
+ @time_2006_08_16_14_00_00 = TIME_2006_08_16_14_00_00
10
10
  end
11
11
 
12
- def test__parse_guess_dates
12
+ def test_parse_guess_dates
13
13
  # rm_sd
14
14
 
15
- time = Chronic.parse("may 27", :now => @time_2006_08_16_14_00_00)
15
+ time = parse_now("may 27")
16
16
  assert_equal Time.local(2007, 5, 27, 12), time
17
17
 
18
- time = Chronic.parse("may 28", :now => @time_2006_08_16_14_00_00, :context => :past)
18
+ time = parse_now("may 28", :context => :past)
19
19
  assert_equal Time.local(2006, 5, 28, 12), time
20
20
 
21
- time = Chronic.parse("may 28 5pm", :now => @time_2006_08_16_14_00_00, :context => :past)
21
+ time = parse_now("may 28 5pm", :context => :past)
22
22
  assert_equal Time.local(2006, 5, 28, 17), time
23
23
 
24
- time = Chronic.parse("may 28 at 5pm", :now => @time_2006_08_16_14_00_00, :context => :past)
24
+ time = parse_now("may 28 at 5pm", :context => :past)
25
25
  assert_equal Time.local(2006, 5, 28, 17), time
26
26
 
27
- time = Chronic.parse("may 28 at 5:32.19pm", :now => @time_2006_08_16_14_00_00, :context => :past)
27
+ time = parse_now("may 28 at 5:32.19pm", :context => :past)
28
28
  assert_equal Time.local(2006, 5, 28, 17, 32, 19), time
29
29
 
30
30
  # rm_od
31
31
 
32
- time = Chronic.parse("may 27th", :now => @time_2006_08_16_14_00_00)
32
+ time = parse_now("may 27th")
33
33
  assert_equal Time.local(2007, 5, 27, 12), time
34
34
 
35
- time = Chronic.parse("may 27th", :now => @time_2006_08_16_14_00_00, :context => :past)
35
+ time = parse_now("may 27th", :context => :past)
36
36
  assert_equal Time.local(2006, 5, 27, 12), time
37
37
 
38
- time = Chronic.parse("may 27th 5:00 pm", :now => @time_2006_08_16_14_00_00, :context => :past)
38
+ time = parse_now("may 27th 5:00 pm", :context => :past)
39
39
  assert_equal Time.local(2006, 5, 27, 17), time
40
40
 
41
- time = Chronic.parse("may 27th at 5pm", :now => @time_2006_08_16_14_00_00, :context => :past)
41
+ time = parse_now("may 27th at 5pm", :context => :past)
42
42
  assert_equal Time.local(2006, 5, 27, 17), time
43
43
 
44
- time = Chronic.parse("may 27th at 5", :now => @time_2006_08_16_14_00_00, :ambiguous_time_range => :none)
44
+ time = parse_now("may 27th at 5", :ambiguous_time_range => :none)
45
45
  assert_equal Time.local(2007, 5, 27, 5), time
46
46
 
47
47
  # rm_sy
48
48
 
49
- time = Chronic.parse("June 1979", :now => @time_2006_08_16_14_00_00)
49
+ time = parse_now("June 1979")
50
50
  assert_equal Time.local(1979, 6, 16, 0), time
51
51
 
52
- time = Chronic.parse("dec 79", :now => @time_2006_08_16_14_00_00)
52
+ time = parse_now("dec 79")
53
53
  assert_equal Time.local(1979, 12, 16, 12), time
54
54
 
55
55
  # rm_sd_sy
56
56
 
57
- time = Chronic.parse("jan 3 2010", :now => @time_2006_08_16_14_00_00)
57
+ time = parse_now("jan 3 2010")
58
58
  assert_equal Time.local(2010, 1, 3, 12), time
59
59
 
60
- time = Chronic.parse("jan 3 2010 midnight", :now => @time_2006_08_16_14_00_00)
60
+ time = parse_now("jan 3 2010 midnight")
61
61
  assert_equal Time.local(2010, 1, 4, 0), time
62
62
 
63
- time = Chronic.parse("jan 3 2010 at midnight", :now => @time_2006_08_16_14_00_00)
63
+ time = parse_now("jan 3 2010 at midnight")
64
64
  assert_equal Time.local(2010, 1, 4, 0), time
65
65
 
66
- time = Chronic.parse("jan 3 2010 at 4", :now => @time_2006_08_16_14_00_00, :ambiguous_time_range => :none)
66
+ time = parse_now("jan 3 2010 at 4", :ambiguous_time_range => :none)
67
67
  assert_equal Time.local(2010, 1, 3, 4), time
68
68
 
69
- #time = Chronic.parse("January 12, '00", :now => @time_2006_08_16_14_00_00)
69
+ #time = parse_now("January 12, '00")
70
70
  #assert_equal Time.local(2000, 1, 12, 12), time
71
71
 
72
- time = Chronic.parse("may 27 79", :now => @time_2006_08_16_14_00_00)
72
+ time = parse_now("may 27 79")
73
73
  assert_equal Time.local(1979, 5, 27, 12), time
74
74
 
75
- time = Chronic.parse("may 27 79 4:30", :now => @time_2006_08_16_14_00_00)
75
+ time = parse_now("may 27 79 4:30")
76
76
  assert_equal Time.local(1979, 5, 27, 16, 30), time
77
77
 
78
- time = Chronic.parse("may 27 79 at 4:30", :now => @time_2006_08_16_14_00_00, :ambiguous_time_range => :none)
78
+ time = parse_now("may 27 79 at 4:30", :ambiguous_time_range => :none)
79
79
  assert_equal Time.local(1979, 5, 27, 4, 30), time
80
80
 
81
81
  # sd_rm_sy
82
82
 
83
- time = Chronic.parse("3 jan 2010", :now => @time_2006_08_16_14_00_00)
83
+ time = parse_now("3 jan 2010")
84
84
  assert_equal Time.local(2010, 1, 3, 12), time
85
85
 
86
- time = Chronic.parse("3 jan 2010 4pm", :now => @time_2006_08_16_14_00_00)
86
+ time = parse_now("3 jan 2010 4pm")
87
87
  assert_equal Time.local(2010, 1, 3, 16), time
88
88
 
89
89
  # sm_sd_sy
90
90
 
91
- time = Chronic.parse("5/27/1979", :now => @time_2006_08_16_14_00_00)
91
+ time = parse_now("5/27/1979")
92
92
  assert_equal Time.local(1979, 5, 27, 12), time
93
93
 
94
- time = Chronic.parse("5/27/1979 4am", :now => @time_2006_08_16_14_00_00)
94
+ time = parse_now("5/27/1979 4am")
95
95
  assert_equal Time.local(1979, 5, 27, 4), time
96
96
 
97
97
  # sd_sm_sy
98
98
 
99
- time = Chronic.parse("27/5/1979", :now => @time_2006_08_16_14_00_00)
99
+ time = parse_now("27/5/1979")
100
100
  assert_equal Time.local(1979, 5, 27, 12), time
101
101
 
102
- time = Chronic.parse("27/5/1979 @ 0700", :now => @time_2006_08_16_14_00_00)
102
+ time = parse_now("27/5/1979 @ 0700")
103
103
  assert_equal Time.local(1979, 5, 27, 7), time
104
104
 
105
105
  # sm_sy
106
106
 
107
- time = Chronic.parse("05/06", :now => @time_2006_08_16_14_00_00)
107
+ time = parse_now("05/06")
108
108
  assert_equal Time.local(2006, 5, 16, 12), time
109
109
 
110
- time = Chronic.parse("12/06", :now => @time_2006_08_16_14_00_00)
110
+ time = parse_now("12/06")
111
111
  assert_equal Time.local(2006, 12, 16, 12), time
112
112
 
113
- time = Chronic.parse("13/06", :now => @time_2006_08_16_14_00_00)
113
+ time = parse_now("13/06")
114
114
  assert_equal nil, time
115
115
 
116
116
  # sy_sm_sd
117
117
 
118
- time = Chronic.parse("2000-1-1", :now => @time_2006_08_16_14_00_00)
118
+ time = parse_now("2000-1-1")
119
119
  assert_equal Time.local(2000, 1, 1, 12), time
120
120
 
121
- time = Chronic.parse("2006-08-20", :now => @time_2006_08_16_14_00_00)
121
+ time = parse_now("2006-08-20")
122
122
  assert_equal Time.local(2006, 8, 20, 12), time
123
123
 
124
- time = Chronic.parse("2006-08-20 7pm", :now => @time_2006_08_16_14_00_00)
124
+ time = parse_now("2006-08-20 7pm")
125
125
  assert_equal Time.local(2006, 8, 20, 19), time
126
126
 
127
- time = Chronic.parse("2006-08-20 03:00", :now => @time_2006_08_16_14_00_00)
127
+ time = parse_now("2006-08-20 03:00")
128
128
  assert_equal Time.local(2006, 8, 20, 3), time
129
129
 
130
- time = Chronic.parse("2006-08-20 03:30:30", :now => @time_2006_08_16_14_00_00)
130
+ time = parse_now("2006-08-20 03:30:30")
131
131
  assert_equal Time.local(2006, 8, 20, 3, 30, 30), time
132
132
 
133
- time = Chronic.parse("2006-08-20 15:30:30", :now => @time_2006_08_16_14_00_00)
133
+ time = parse_now("2006-08-20 15:30:30")
134
134
  assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
135
135
 
136
- time = Chronic.parse("2006-08-20 15:30.30", :now => @time_2006_08_16_14_00_00)
136
+ time = parse_now("2006-08-20 15:30.30")
137
137
  assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
138
138
 
139
139
  # rm_sd_rt
140
140
 
141
- #time = Chronic.parse("jan 5 13:00", :now => @time_2006_08_16_14_00_00)
141
+ #time = parse_now("jan 5 13:00")
142
142
  #assert_equal Time.local(2007, 1, 5, 13), time
143
143
 
144
144
  # due to limitations of the Time class, these don't work
145
145
 
146
- time = Chronic.parse("may 40", :now => @time_2006_08_16_14_00_00)
146
+ time = parse_now("may 40")
147
147
  assert_equal nil, time
148
148
 
149
- time = Chronic.parse("may 27 40", :now => @time_2006_08_16_14_00_00)
149
+ time = parse_now("may 27 40")
150
150
  assert_equal nil, time
151
151
 
152
- time = Chronic.parse("1800-08-20", :now => @time_2006_08_16_14_00_00)
152
+ time = parse_now("1800-08-20")
153
153
  assert_equal nil, time
154
154
  end
155
155
 
156
156
  def test_parse_guess_r
157
- time = Chronic.parse("friday", :now => @time_2006_08_16_14_00_00)
157
+ time = parse_now("friday")
158
158
  assert_equal Time.local(2006, 8, 18, 12), time
159
159
 
160
- time = Chronic.parse("5", :now => @time_2006_08_16_14_00_00)
160
+ time = parse_now("5")
161
161
  assert_equal Time.local(2006, 8, 16, 17), time
162
162
 
163
- time = Chronic.parse("5", :now => @time_2006_08_16_03_00_00, :ambiguous_time_range => :none)
163
+ time = Chronic.parse("5", :now => Time.local(2006, 8, 16, 3, 0, 0, 0), :ambiguous_time_range => :none)
164
164
  assert_equal Time.local(2006, 8, 16, 5), time
165
165
 
166
- time = Chronic.parse("13:00", :now => @time_2006_08_16_14_00_00)
166
+ time = parse_now("13:00")
167
167
  assert_equal Time.local(2006, 8, 17, 13), time
168
168
 
169
- time = Chronic.parse("13:45", :now => @time_2006_08_16_14_00_00)
169
+ time = parse_now("13:45")
170
170
  assert_equal Time.local(2006, 8, 17, 13, 45), time
171
171
 
172
- time = Chronic.parse("november", :now => @time_2006_08_16_14_00_00)
172
+ time = parse_now("november")
173
173
  assert_equal Time.local(2006, 11, 16), time
174
174
  end
175
175
 
176
176
  def test_parse_guess_rr
177
- time = Chronic.parse("friday 13:00", :now => @time_2006_08_16_14_00_00)
177
+ time = parse_now("friday 13:00")
178
178
  assert_equal Time.local(2006, 8, 18, 13), time
179
179
 
180
- time = Chronic.parse("monday 4:00", :now => @time_2006_08_16_14_00_00)
180
+ time = parse_now("monday 4:00")
181
181
  assert_equal Time.local(2006, 8, 21, 16), time
182
182
 
183
- time = Chronic.parse("sat 4:00", :now => @time_2006_08_16_14_00_00, :ambiguous_time_range => :none)
183
+ time = parse_now("sat 4:00", :ambiguous_time_range => :none)
184
184
  assert_equal Time.local(2006, 8, 19, 4), time
185
185
 
186
- time = Chronic.parse("sunday 4:20", :now => @time_2006_08_16_14_00_00, :ambiguous_time_range => :none)
186
+ time = parse_now("sunday 4:20", :ambiguous_time_range => :none)
187
187
  assert_equal Time.local(2006, 8, 20, 4, 20), time
188
188
 
189
- time = Chronic.parse("4 pm", :now => @time_2006_08_16_14_00_00)
189
+ time = parse_now("4 pm")
190
190
  assert_equal Time.local(2006, 8, 16, 16), time
191
191
 
192
- time = Chronic.parse("4 am", :now => @time_2006_08_16_14_00_00, :ambiguous_time_range => :none)
192
+ time = parse_now("4 am", :ambiguous_time_range => :none)
193
193
  assert_equal Time.local(2006, 8, 16, 4), time
194
194
 
195
- time = Chronic.parse("4:00 in the morning", :now => @time_2006_08_16_14_00_00)
195
+ time = parse_now("4:00 in the morning")
196
196
  assert_equal Time.local(2006, 8, 16, 4), time
197
197
 
198
- time = Chronic.parse("november 4", :now => @time_2006_08_16_14_00_00)
198
+ time = parse_now("november 4")
199
199
  assert_equal Time.local(2006, 11, 4, 12), time
200
200
 
201
- time = Chronic.parse("aug 24", :now => @time_2006_08_16_14_00_00)
201
+ time = parse_now("aug 24")
202
202
  assert_equal Time.local(2006, 8, 24, 12), time
203
203
  end
204
204
 
205
205
  def test_parse_guess_rrr
206
- time = Chronic.parse("friday 1 pm", :now => @time_2006_08_16_14_00_00)
206
+ time = parse_now("friday 1 pm")
207
207
  assert_equal Time.local(2006, 8, 18, 13), time
208
208
 
209
- time = Chronic.parse("friday 11 at night", :now => @time_2006_08_16_14_00_00)
209
+ time = parse_now("friday 11 at night")
210
210
  assert_equal Time.local(2006, 8, 18, 23), time
211
211
 
212
- time = Chronic.parse("friday 11 in the evening", :now => @time_2006_08_16_14_00_00)
212
+ time = parse_now("friday 11 in the evening")
213
213
  assert_equal Time.local(2006, 8, 18, 23), time
214
214
 
215
- time = Chronic.parse("sunday 6am", :now => @time_2006_08_16_14_00_00)
215
+ time = parse_now("sunday 6am")
216
216
  assert_equal Time.local(2006, 8, 20, 6), time
217
217
  end
218
218
 
219
219
  def test_parse_guess_gr
220
220
  # year
221
221
 
222
- time = Chronic.parse("this year", :now => @time_2006_08_16_14_00_00)
222
+ time = parse_now("this year")
223
223
  assert_equal Time.local(2006, 10, 24, 12, 30), time
224
224
 
225
- time = Chronic.parse("this year", :now => @time_2006_08_16_14_00_00, :context => :past)
225
+ time = parse_now("this year", :context => :past)
226
226
  assert_equal Time.local(2006, 4, 24, 12, 30), time
227
227
 
228
228
  # month
229
229
 
230
- time = Chronic.parse("this month", :now => @time_2006_08_16_14_00_00)
230
+ time = parse_now("this month")
231
231
  assert_equal Time.local(2006, 8, 24, 12), time
232
232
 
233
- time = Chronic.parse("this month", :now => @time_2006_08_16_14_00_00, :context => :past)
233
+ time = parse_now("this month", :context => :past)
234
234
  assert_equal Time.local(2006, 8, 8, 12), time
235
235
 
236
236
  # month name
237
237
 
238
- time = Chronic.parse("last november", :now => @time_2006_08_16_14_00_00)
238
+ time = parse_now("last november")
239
239
  assert_equal Time.local(2005, 11, 16), time
240
240
 
241
241
  # fortnight
242
242
 
243
- time = Chronic.parse("this fortnight", :now => @time_2006_08_16_14_00_00)
243
+ time = parse_now("this fortnight")
244
244
  assert_equal Time.local(2006, 8, 21, 19, 30), time
245
245
 
246
- time = Chronic.parse("this fortnight", :now => @time_2006_08_16_14_00_00, :context => :past)
246
+ time = parse_now("this fortnight", :context => :past)
247
247
  assert_equal Time.local(2006, 8, 14, 19), time
248
248
 
249
249
  # week
250
250
 
251
- time = Chronic.parse("this week", :now => @time_2006_08_16_14_00_00)
251
+ time = parse_now("this week")
252
252
  assert_equal Time.local(2006, 8, 18, 7, 30), time
253
253
 
254
- time = Chronic.parse("this week", :now => @time_2006_08_16_14_00_00, :context => :past)
254
+ time = parse_now("this week", :context => :past)
255
255
  assert_equal Time.local(2006, 8, 14, 19), time
256
256
 
257
257
  # weekend
258
258
 
259
- time = Chronic.parse("this weekend", :now => @time_2006_08_16_14_00_00)
259
+ time = parse_now("this weekend")
260
260
  assert_equal Time.local(2006, 8, 20), time
261
261
 
262
- time = Chronic.parse("this weekend", :now => @time_2006_08_16_14_00_00, :context => :past)
262
+ time = parse_now("this weekend", :context => :past)
263
263
  assert_equal Time.local(2006, 8, 13), time
264
264
 
265
- time = Chronic.parse("last weekend", :now => @time_2006_08_16_14_00_00)
265
+ time = parse_now("last weekend")
266
266
  assert_equal Time.local(2006, 8, 13), time
267
267
 
268
268
  # day
269
269
 
270
- time = Chronic.parse("this day", :now => @time_2006_08_16_14_00_00)
270
+ time = parse_now("this day")
271
271
  assert_equal Time.local(2006, 8, 16, 19, 30), time
272
272
 
273
- time = Chronic.parse("this day", :now => @time_2006_08_16_14_00_00, :context => :past)
273
+ time = parse_now("this day", :context => :past)
274
274
  assert_equal Time.local(2006, 8, 16, 7), time
275
275
 
276
- time = Chronic.parse("today", :now => @time_2006_08_16_14_00_00)
276
+ time = parse_now("today")
277
277
  assert_equal Time.local(2006, 8, 16, 19, 30), time
278
278
 
279
- time = Chronic.parse("yesterday", :now => @time_2006_08_16_14_00_00)
279
+ time = parse_now("yesterday")
280
280
  assert_equal Time.local(2006, 8, 15, 12), time
281
281
 
282
- time = Chronic.parse("tomorrow", :now => @time_2006_08_16_14_00_00)
282
+ time = parse_now("tomorrow")
283
283
  assert_equal Time.local(2006, 8, 17, 12), time
284
284
 
285
285
  # day name
286
286
 
287
- time = Chronic.parse("this tuesday", :now => @time_2006_08_16_14_00_00)
287
+ time = parse_now("this tuesday")
288
288
  assert_equal Time.local(2006, 8, 22, 12), time
289
289
 
290
- time = Chronic.parse("next tuesday", :now => @time_2006_08_16_14_00_00)
290
+ time = parse_now("next tuesday")
291
291
  assert_equal Time.local(2006, 8, 22, 12), time
292
292
 
293
- time = Chronic.parse("last tuesday", :now => @time_2006_08_16_14_00_00)
293
+ time = parse_now("last tuesday")
294
294
  assert_equal Time.local(2006, 8, 15, 12), time
295
295
 
296
- time = Chronic.parse("this wed", :now => @time_2006_08_16_14_00_00)
296
+ time = parse_now("this wed")
297
297
  assert_equal Time.local(2006, 8, 23, 12), time
298
298
 
299
- time = Chronic.parse("next wed", :now => @time_2006_08_16_14_00_00)
299
+ time = parse_now("next wed")
300
300
  assert_equal Time.local(2006, 8, 23, 12), time
301
301
 
302
- time = Chronic.parse("last wed", :now => @time_2006_08_16_14_00_00)
302
+ time = parse_now("last wed")
303
303
  assert_equal Time.local(2006, 8, 9, 12), time
304
304
 
305
305
  # day portion
306
306
 
307
- time = Chronic.parse("this morning", :now => @time_2006_08_16_14_00_00)
307
+ time = parse_now("this morning")
308
308
  assert_equal Time.local(2006, 8, 16, 9), time
309
309
 
310
- time = Chronic.parse("tonight", :now => @time_2006_08_16_14_00_00)
310
+ time = parse_now("tonight")
311
311
  assert_equal Time.local(2006, 8, 16, 22), time
312
312
 
313
313
  # second
314
314
 
315
- time = Chronic.parse("this second", :now => @time_2006_08_16_14_00_00)
315
+ time = parse_now("this second")
316
316
  assert_equal Time.local(2006, 8, 16, 14), time
317
317
 
318
- time = Chronic.parse("this second", :now => @time_2006_08_16_14_00_00, :context => :past)
318
+ time = parse_now("this second", :context => :past)
319
319
  assert_equal Time.local(2006, 8, 16, 14), time
320
320
 
321
- time = Chronic.parse("next second", :now => @time_2006_08_16_14_00_00)
321
+ time = parse_now("next second")
322
322
  assert_equal Time.local(2006, 8, 16, 14, 0, 1), time
323
323
 
324
- time = Chronic.parse("last second", :now => @time_2006_08_16_14_00_00)
324
+ time = parse_now("last second")
325
325
  assert_equal Time.local(2006, 8, 16, 13, 59, 59), time
326
326
  end
327
327
 
328
328
  def test_parse_guess_grr
329
- time = Chronic.parse("yesterday at 4:00", :now => @time_2006_08_16_14_00_00)
329
+ time = parse_now("yesterday at 4:00")
330
330
  assert_equal Time.local(2006, 8, 15, 16), time
331
331
 
332
- time = Chronic.parse("today at 9:00", :now => @time_2006_08_16_14_00_00)
332
+ time = parse_now("today at 9:00")
333
333
  assert_equal Time.local(2006, 8, 16, 9), time
334
334
 
335
- time = Chronic.parse("today at 2100", :now => @time_2006_08_16_14_00_00)
335
+ time = parse_now("today at 2100")
336
336
  assert_equal Time.local(2006, 8, 16, 21), time
337
337
 
338
- time = Chronic.parse("this day at 0900", :now => @time_2006_08_16_14_00_00)
338
+ time = parse_now("this day at 0900")
339
339
  assert_equal Time.local(2006, 8, 16, 9), time
340
340
 
341
- time = Chronic.parse("tomorrow at 0900", :now => @time_2006_08_16_14_00_00)
341
+ time = parse_now("tomorrow at 0900")
342
342
  assert_equal Time.local(2006, 8, 17, 9), time
343
343
 
344
- time = Chronic.parse("yesterday at 4:00", :now => @time_2006_08_16_14_00_00, :ambiguous_time_range => :none)
344
+ time = parse_now("yesterday at 4:00", :ambiguous_time_range => :none)
345
345
  assert_equal Time.local(2006, 8, 15, 4), time
346
346
 
347
- time = Chronic.parse("last friday at 4:00", :now => @time_2006_08_16_14_00_00)
347
+ time = parse_now("last friday at 4:00")
348
348
  assert_equal Time.local(2006, 8, 11, 16), time
349
349
 
350
- time = Chronic.parse("next wed 4:00", :now => @time_2006_08_16_14_00_00)
350
+ time = parse_now("next wed 4:00")
351
351
  assert_equal Time.local(2006, 8, 23, 16), time
352
352
 
353
- time = Chronic.parse("yesterday afternoon", :now => @time_2006_08_16_14_00_00)
353
+ time = parse_now("yesterday afternoon")
354
354
  assert_equal Time.local(2006, 8, 15, 15), time
355
355
 
356
- time = Chronic.parse("last week tuesday", :now => @time_2006_08_16_14_00_00)
356
+ time = parse_now("last week tuesday")
357
357
  assert_equal Time.local(2006, 8, 8, 12), time
358
358
  end
359
359
 
360
360
  def test_parse_guess_grrr
361
- time = Chronic.parse("today at 6:00pm", :now => @time_2006_08_16_14_00_00)
361
+ time = parse_now("today at 6:00pm")
362
362
  assert_equal Time.local(2006, 8, 16, 18), time
363
363
 
364
- time = Chronic.parse("today at 6:00am", :now => @time_2006_08_16_14_00_00)
364
+ time = parse_now("today at 6:00am")
365
365
  assert_equal Time.local(2006, 8, 16, 6), time
366
366
 
367
- time = Chronic.parse("this day 1800", :now => @time_2006_08_16_14_00_00)
367
+ time = parse_now("this day 1800")
368
368
  assert_equal Time.local(2006, 8, 16, 18), time
369
369
 
370
- time = Chronic.parse("yesterday at 4:00pm", :now => @time_2006_08_16_14_00_00)
370
+ time = parse_now("yesterday at 4:00pm")
371
371
  assert_equal Time.local(2006, 8, 15, 16), time
372
372
  end
373
373
 
374
374
  def test_parse_guess_rgr
375
- time = Chronic.parse("afternoon yesterday", :now => @time_2006_08_16_14_00_00)
375
+ time = parse_now("afternoon yesterday")
376
376
  assert_equal Time.local(2006, 8, 15, 15), time
377
377
 
378
- time = Chronic.parse("tuesday last week", :now => @time_2006_08_16_14_00_00)
378
+ time = parse_now("tuesday last week")
379
379
  assert_equal Time.local(2006, 8, 8, 12), time
380
380
  end
381
381
 
382
382
  def test_parse_guess_s_r_p
383
383
  # past
384
384
 
385
- time = Chronic.parse("3 years ago", :now => @time_2006_08_16_14_00_00)
386
- assert_equal Time.local(2003, 8, 16, 14, 30, 30), time
385
+ time = parse_now("3 years ago")
386
+ assert_equal Time.local(2003, 8, 16, 14), time
387
387
 
388
- time = Chronic.parse("1 month ago", :now => @time_2006_08_16_14_00_00)
389
- assert_equal Time.local(2006, 7, 16, 14, 30, 30), time
388
+ time = parse_now("1 month ago")
389
+ assert_equal Time.local(2006, 7, 16, 14), time
390
390
 
391
- time = Chronic.parse("1 fortnight ago", :now => @time_2006_08_16_14_00_00)
392
- assert_equal Time.local(2006, 8, 2, 14, 30, 30), time
391
+ time = parse_now("1 fortnight ago")
392
+ assert_equal Time.local(2006, 8, 2, 14), time
393
393
 
394
- time = Chronic.parse("2 fortnights ago", :now => @time_2006_08_16_14_00_00)
395
- assert_equal Time.local(2006, 7, 19, 14, 30, 30), time
394
+ time = parse_now("2 fortnights ago")
395
+ assert_equal Time.local(2006, 7, 19, 14), time
396
396
 
397
- time = Chronic.parse("3 weeks ago", :now => @time_2006_08_16_14_00_00)
398
- assert_equal Time.local(2006, 7, 26, 14, 30, 30), time
397
+ time = parse_now("3 weeks ago")
398
+ assert_equal Time.local(2006, 7, 26, 14), time
399
399
 
400
- time = Chronic.parse("2 weekends ago", :now => @time_2006_08_16_14_00_00)
400
+ time = parse_now("2 weekends ago")
401
401
  assert_equal Time.local(2006, 8, 5), time
402
402
 
403
- time = Chronic.parse("3 days ago", :now => @time_2006_08_16_14_00_00)
403
+ time = parse_now("3 days ago")
404
404
  assert_equal Time.local(2006, 8, 13, 14), time
405
405
 
406
- #time = Chronic.parse("1 monday ago", :now => @time_2006_08_16_14_00_00)
406
+ #time = parse_now("1 monday ago")
407
407
  #assert_equal Time.local(2006, 8, 14, 12), time
408
408
 
409
- time = Chronic.parse("5 mornings ago", :now => @time_2006_08_16_14_00_00)
409
+ time = parse_now("5 mornings ago")
410
410
  assert_equal Time.local(2006, 8, 12, 9), time
411
411
 
412
- time = Chronic.parse("7 hours ago", :now => @time_2006_08_16_14_00_00)
412
+ time = parse_now("7 hours ago")
413
413
  assert_equal Time.local(2006, 8, 16, 7), time
414
414
 
415
- time = Chronic.parse("3 minutes ago", :now => @time_2006_08_16_14_00_00)
415
+ time = parse_now("3 minutes ago")
416
416
  assert_equal Time.local(2006, 8, 16, 13, 57), time
417
417
 
418
- time = Chronic.parse("20 seconds before now", :now => @time_2006_08_16_14_00_00)
418
+ time = parse_now("20 seconds before now")
419
419
  assert_equal Time.local(2006, 8, 16, 13, 59, 40), time
420
420
 
421
421
  # future
422
422
 
423
- time = Chronic.parse("3 years from now", :now => @time_2006_08_16_14_00_00)
423
+ time = parse_now("3 years from now")
424
424
  assert_equal Time.local(2009, 8, 16, 14, 0, 0), time
425
425
 
426
- time = Chronic.parse("6 months hence", :now => @time_2006_08_16_14_00_00)
427
- assert_equal Time.local(2007, 2, 16, 14, 30, 30), time
426
+ time = parse_now("6 months hence")
427
+ assert_equal Time.local(2007, 2, 16, 14), time
428
428
 
429
- time = Chronic.parse("3 fortnights hence", :now => @time_2006_08_16_14_00_00)
430
- assert_equal Time.local(2006, 9, 27, 14, 30, 30), time
429
+ time = parse_now("3 fortnights hence")
430
+ assert_equal Time.local(2006, 9, 27, 14), time
431
431
 
432
- time = Chronic.parse("1 week from now", :now => @time_2006_08_16_14_00_00)
432
+ time = parse_now("1 week from now")
433
433
  assert_equal Time.local(2006, 8, 23, 14, 0, 0), time
434
434
 
435
- time = Chronic.parse("1 weekend from now", :now => @time_2006_08_16_14_00_00)
435
+ time = parse_now("1 weekend from now")
436
436
  assert_equal Time.local(2006, 8, 19), time
437
437
 
438
- time = Chronic.parse("2 weekends from now", :now => @time_2006_08_16_14_00_00)
438
+ time = parse_now("2 weekends from now")
439
439
  assert_equal Time.local(2006, 8, 26), time
440
440
 
441
- time = Chronic.parse("1 day hence", :now => @time_2006_08_16_14_00_00)
441
+ time = parse_now("1 day hence")
442
442
  assert_equal Time.local(2006, 8, 17, 14), time
443
443
 
444
- time = Chronic.parse("5 mornings hence", :now => @time_2006_08_16_14_00_00)
444
+ time = parse_now("5 mornings hence")
445
445
  assert_equal Time.local(2006, 8, 21, 9), time
446
446
 
447
- time = Chronic.parse("1 hour from now", :now => @time_2006_08_16_14_00_00)
447
+ time = parse_now("1 hour from now")
448
448
  assert_equal Time.local(2006, 8, 16, 15), time
449
449
 
450
- time = Chronic.parse("20 minutes hence", :now => @time_2006_08_16_14_00_00)
450
+ time = parse_now("20 minutes hence")
451
451
  assert_equal Time.local(2006, 8, 16, 14, 20), time
452
452
 
453
- time = Chronic.parse("20 seconds from now", :now => @time_2006_08_16_14_00_00)
453
+ time = parse_now("20 seconds from now")
454
454
  assert_equal Time.local(2006, 8, 16, 14, 0, 20), time
455
+
456
+ time = Chronic.parse("2 months ago", :now => Time.parse("2007-03-07 23:30"))
457
+ assert_equal Time.local(2007, 1, 7, 23, 30), time
455
458
  end
456
459
 
457
460
  def test_parse_guess_p_s_r
458
- time = Chronic.parse("in 3 hours", :now => @time_2006_08_16_14_00_00)
461
+ time = parse_now("in 3 hours")
459
462
  assert_equal Time.local(2006, 8, 16, 17), time
460
463
  end
461
464
 
462
465
  def test_parse_guess_s_r_p_a
463
466
  # past
464
467
 
465
- time = Chronic.parse("3 years ago tomorrow", :now => @time_2006_08_16_14_00_00)
468
+ time = parse_now("3 years ago tomorrow")
466
469
  assert_equal Time.local(2003, 8, 17, 12), time
467
470
 
468
- time = Chronic.parse("3 years ago this friday", :now => @time_2006_08_16_14_00_00)
471
+ time = parse_now("3 years ago this friday")
469
472
  assert_equal Time.local(2003, 8, 18, 12), time
470
473
 
471
- time = Chronic.parse("3 months ago saturday at 5:00 pm", :now => @time_2006_08_16_14_00_00)
474
+ time = parse_now("3 months ago saturday at 5:00 pm")
472
475
  assert_equal Time.local(2006, 5, 19, 17), time
473
476
 
474
- time = Chronic.parse("2 days from this second", :now => @time_2006_08_16_14_00_00)
477
+ time = parse_now("2 days from this second")
475
478
  assert_equal Time.local(2006, 8, 18, 14), time
476
479
 
477
- time = Chronic.parse("7 hours before tomorrow at midnight", :now => @time_2006_08_16_14_00_00)
480
+ time = parse_now("7 hours before tomorrow at midnight")
478
481
  assert_equal Time.local(2006, 8, 17, 17), time
479
482
 
480
483
  # future
481
484
  end
482
485
 
483
486
  def test_parse_guess_o_r_s_r
484
- time = Chronic.parse("3rd wednesday in november", :now => @time_2006_08_16_14_00_00)
487
+ time = parse_now("3rd wednesday in november")
485
488
  assert_equal Time.local(2006, 11, 15, 12), time
486
489
 
487
- time = Chronic.parse("10th wednesday in november", :now => @time_2006_08_16_14_00_00)
490
+ time = parse_now("10th wednesday in november")
488
491
  assert_equal nil, time
489
492
  end
490
493
 
491
494
  def test_parse_guess_o_r_g_r
492
- time = Chronic.parse("3rd month next year", :now => @time_2006_08_16_14_00_00)
495
+ time = parse_now("3rd month next year")
493
496
  assert_equal Time.local(2007, 3, 16, 12, 30), time
494
497
 
495
- time = Chronic.parse("3rd thursday this september", :now => @time_2006_08_16_14_00_00)
498
+ time = parse_now("3rd thursday this september")
496
499
  assert_equal Time.local(2006, 9, 21, 12), time
497
500
 
498
- time = Chronic.parse("4th day last week", :now => @time_2006_08_16_14_00_00)
501
+ time = parse_now("4th day last week")
499
502
  assert_equal Time.local(2006, 8, 9, 12), time
500
503
  end
501
504
 
502
505
  def test_parse_guess_nonsense
503
- time = Chronic.parse("some stupid nonsense", :now => @time_2006_08_16_14_00_00)
506
+ time = parse_now("some stupid nonsense")
504
507
  assert_equal nil, time
505
508
  end
506
509
 
507
510
  def test_parse_span
508
- span = Chronic.parse("friday", :now => @time_2006_08_16_14_00_00, :guess => false)
511
+ span = parse_now("friday", :guess => false)
509
512
  assert_equal Time.local(2006, 8, 18), span.begin
510
513
  assert_equal Time.local(2006, 8, 19), span.end
511
514
 
512
- span = Chronic.parse("november", :now => @time_2006_08_16_14_00_00, :guess => false)
515
+ span = parse_now("november", :guess => false)
513
516
  assert_equal Time.local(2006, 11), span.begin
514
517
  assert_equal Time.local(2006, 12), span.end
515
518
 
@@ -518,6 +521,18 @@ class TestParsing < Test::Unit::TestCase
518
521
  assert_equal Time.local(2006, 8, 21), span.end
519
522
  end
520
523
 
524
+ def test_parse_words
525
+ assert_equal parse_now("33 days from now"), parse_now("thirty-three days from now")
526
+ 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")
527
+ assert_equal parse_now("may 10th"), parse_now("may tenth")
528
+ end
529
+
530
+ def test_parse_only_complete_pointers
531
+ assert_equal parse_now("eat pasty buns today at 2pm"), @time_2006_08_16_14_00_00
532
+ assert_equal parse_now("futuristically speaking today at 2pm"), @time_2006_08_16_14_00_00
533
+ assert_equal parse_now("meeting today at 2pm"), @time_2006_08_16_14_00_00
534
+ end
535
+
521
536
  def test_argument_validation
522
537
  assert_raise(Chronic::InvalidArgumentException) do
523
538
  time = Chronic.parse("may 27", :foo => :bar)
@@ -528,4 +543,8 @@ class TestParsing < Test::Unit::TestCase
528
543
  end
529
544
  end
530
545
 
546
+ private
547
+ def parse_now(string, options={})
548
+ Chronic.parse(string, {:now => TIME_2006_08_16_14_00_00 }.merge(options))
549
+ end
531
550
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: chronic
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.6
7
- date: 2007-01-15 00:00:00 -08:00
6
+ version: 0.2.0
7
+ date: 2007-03-20 00:00:00 -07:00
8
8
  summary: A natural language date parser
9
9
  require_paths:
10
10
  - lib
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Ryan Davis
30
31
  files:
@@ -56,10 +57,11 @@ files:
56
57
  - lib/chronic/repeaters/repeater_year.rb
57
58
  - lib/chronic/scalar.rb
58
59
  - lib/chronic/separator.rb
59
- - test/parse_numbers.rb
60
+ - lib/numerizer/numerizer.rb
60
61
  - test/suite.rb
61
62
  - test/test_Chronic.rb
62
63
  - test/test_Handler.rb
64
+ - test/test_Numerizer.rb
63
65
  - test/test_RepeaterDayName.rb
64
66
  - test/test_RepeaterFortnight.rb
65
67
  - test/test_RepeaterHour.rb
@@ -67,6 +69,7 @@ files:
67
69
  - test/test_RepeaterMonthName.rb
68
70
  - test/test_RepeaterTime.rb
69
71
  - test/test_RepeaterWeek.rb
72
+ - test/test_RepeaterWeekend.rb
70
73
  - test/test_RepeaterYear.rb
71
74
  - test/test_Span.rb
72
75
  - test/test_Token.rb
@@ -74,6 +77,7 @@ files:
74
77
  test_files:
75
78
  - test/test_Chronic.rb
76
79
  - test/test_Handler.rb
80
+ - test/test_Numerizer.rb
77
81
  - test/test_parsing.rb
78
82
  - test/test_RepeaterDayName.rb
79
83
  - test/test_RepeaterFortnight.rb
@@ -96,5 +100,13 @@ extensions: []
96
100
 
97
101
  requirements: []
98
102
 
99
- dependencies: []
100
-
103
+ dependencies:
104
+ - !ruby/object:Gem::Dependency
105
+ name: hoe
106
+ version_requirement:
107
+ version_requirements: !ruby/object:Gem::Version::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 1.2.0
112
+ version: