public
Description: Chronic is a pure Ruby natural language date parser.
Homepage: http://chronic.rubyforge.org
Clone URL: git://github.com/mojombo/chronic.git
Search Repo:
bug fixes, seconds for all dates, hoe
mojombo (author)
Mon Jan 15 17:35:36 -0800 2007
commit  7f3625b55aa203738dcdeaabe0588135ab44b594
tree    1b3f1e347062850a09213040da43f0315ba4a0e4
parent  2929d1069221911b0f623eb67ffc5fbdec569930
...
2
3
4
5
 
6
7
8
...
2
3
4
 
5
6
7
8
0
@@ -2,7 +2,7 @@ require 'rubygems'
0
 
0
 SPEC = Gem::Specification.new do |s|
0
   s.name = 'chronic'
0
- s.version = '0.1.4'
0
+ s.version = '0.1.5'
0
   s.author = 'Tom Preston-Werner'
0
   s.email = 'tom@rubyisawesome.com'
0
   s.homepage = 'http://chronic.rubyforge.org'
...
34
35
36
 
 
37
38
39
 
 
 
 
 
 
40
...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
0
@@ -34,6 +34,14 @@ require 'chronic/ordinal'
0
 require 'chronic/separator'
0
 
0
 module Chronic
0
+ VERSION = "0.1.5"
0
+
0
   def self.debug; false; end
0
 end
0
 
0
+alias p_orig p
0
+
0
+def p(val)
0
+ p_orig val
0
+ puts
0
+end
0
\ No newline at end of file
...
108
109
110
111
112
113
114
...
108
109
110
 
111
112
113
0
@@ -108,7 +108,6 @@ module Chronic
0
       normalized_text.gsub!(/\byesterday\b/, 'last day')
0
       normalized_text.gsub!(/\bnoon\b/, '12:00')
0
       normalized_text.gsub!(/\bmidnight\b/, '24:00')
0
- normalized_text.gsub!(/\bfrom now\b/, 'future')
0
       normalized_text.gsub!(/\bbefore now\b/, 'past')
0
       normalized_text.gsub!(/\bnow\b/, 'this second')
0
       normalized_text.gsub!(/\b(ago|before)\b/, 'past')
...
88
89
90
91
 
92
93
94
...
213
214
215
216
 
217
218
219
...
88
89
90
 
91
92
93
94
...
213
214
215
 
216
217
218
219
0
@@ -88,7 +88,7 @@ module Chronic
0
     
0
     def handle_m_d(month, day, time_tokens, options) #:nodoc:
0
       month.start = @now
0
- span = month.next(options[:context])
0
+ span = month.this(options[:context])
0
       
0
       day_start = Time.local(span.begin.year, span.begin.month, day)
0
       
0
@@ -213,7 +213,7 @@ module Chronic
0
     
0
     def handle_s_r_p(tokens, options) #:nodoc:
0
       repeater = tokens[1].get_tag(Repeater)
0
-
0
+
0
       span =
0
       case true
0
       when [RepeaterYear, RepeaterSeason, RepeaterSeasonName, RepeaterMonth, RepeaterMonthName, RepeaterFortnight, RepeaterWeek].include?(repeater.class)
...
60
61
62
63
 
64
65
66
...
99
100
101
102
 
103
104
105
...
60
61
62
 
63
64
65
66
...
99
100
101
 
102
103
104
105
0
@@ -60,7 +60,7 @@ class Chronic::Repeater < Chronic::Tag #:nodoc:
0
   end
0
   
0
   def self.scan_for_times(token, options)
0
- if token.word =~ /^\d{1,2}(:?\d{2})?$/
0
+ if token.word =~ /^\d{1,2}(:?\d{2})?([\.:]?\d{2})?$/
0
       return Chronic::RepeaterTime.new(token.word, options)
0
     end
0
     return nil
0
@@ -99,7 +99,7 @@ class Chronic::Repeater < Chronic::Tag #:nodoc:
0
   # returns the next occurance of this repeatable.
0
   def next(pointer)
0
     !@now.nil? || raise("Start point must be set before calling #next")
0
- [:future, :past].include?(pointer) || raise("First argument 'pointer' must be one of :past or :future")
0
+ [:future, :none, :past].include?(pointer) || raise("First argument 'pointer' must be one of :past or :future")
0
     #raise("Repeatable#next must be overridden in subclasses")
0
   end
0
   
...
13
14
15
 
 
 
 
 
 
16
17
18
...
47
48
49
50
51
52
 
 
 
 
 
 
53
54
55
...
13
14
15
16
17
18
19
20
21
22
23
24
...
53
54
55
 
 
 
56
57
58
59
60
61
62
63
64
0
@@ -13,6 +13,12 @@ class Chronic::RepeaterMonthName < Chronic::Repeater #:nodoc:
0
         else @now.month > target_month
0
           @current_month_begin = Time.local(@now.year + 1, target_month)
0
         end
0
+ when :none
0
+ if @now.month <= target_month
0
+ @current_month_begin = Time.local(@now.year, target_month)
0
+ else @now.month > target_month
0
+ @current_month_begin = Time.local(@now.year + 1, target_month)
0
+ end
0
       when :past
0
         if @now.month > target_month
0
           @current_month_begin = Time.local(@now.year, target_month)
0
@@ -47,9 +53,12 @@ class Chronic::RepeaterMonthName < Chronic::Repeater #:nodoc:
0
   def this(pointer = :future)
0
     super
0
     
0
- pointer = :future if pointer == :none
0
-
0
- self.next(pointer)
0
+ case pointer
0
+ when :past
0
+ self.next(pointer)
0
+ when :future, :none
0
+ self.next(:none)
0
+ end
0
   end
0
   
0
   def width
...
25
26
27
28
 
29
30
31
...
34
35
36
 
 
 
 
 
37
38
 
39
40
41
...
25
26
27
 
28
29
30
31
...
34
35
36
37
38
39
40
41
42
 
43
44
45
46
0
@@ -25,7 +25,7 @@ class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
0
   end
0
   
0
   def initialize(time, options = {})
0
- t = time.sub(/\:/, '')
0
+ t = time.gsub(/\:/, '')
0
     @type =
0
     if (1..2) === t.size
0
       Tick.new(t.to_i * 60 * 60, true)
0
@@ -34,8 +34,13 @@ class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
0
     elsif t.size == 4
0
       ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
0
       Tick.new(t[0..1].to_i * 60 * 60 + t[2..3].to_i * 60, ambiguous)
0
+ elsif t.size == 5
0
+ Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
0
+ elsif t.size == 6
0
+ ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
0
+ Tick.new(t[0..1].to_i * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
0
     else
0
- raise("Time cannot exceed four digits")
0
+ raise("Time cannot exceed six digits")
0
     end
0
   end
0
   
...
24
25
26
 
 
 
27
28
29
...
124
125
126
 
 
 
 
 
 
 
 
 
127
128
129
...
183
184
185
186
187
 
 
 
 
 
188
189
190
...
392
393
394
395
 
396
397
398
...
401
402
403
404
 
405
406
407
...
24
25
26
27
28
29
30
31
32
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
195
196
197
 
 
198
199
200
201
202
203
204
205
...
407
408
409
 
410
411
412
413
...
416
417
418
 
419
420
421
422
0
@@ -24,6 +24,9 @@ class TestParsing < Test::Unit::TestCase
0
     time = Chronic.parse("may 28 at 5pm", :now => @time_2006_08_16_14_00_00, :context => :past)
0
     assert_equal Time.local(2006, 5, 28, 17), time
0
     
0
+ time = Chronic.parse("may 28 at 5:32.19pm", :now => @time_2006_08_16_14_00_00, :context => :past)
0
+ assert_equal Time.local(2006, 5, 28, 17, 32, 19), time
0
+
0
     # rm_od
0
     
0
     time = Chronic.parse("may 27th", :now => @time_2006_08_16_14_00_00)
0
@@ -124,6 +127,15 @@ class TestParsing < Test::Unit::TestCase
0
     time = Chronic.parse("2006-08-20 03:00", :now => @time_2006_08_16_14_00_00)
0
     assert_equal Time.local(2006, 8, 20, 3), time
0
     
0
+ time = Chronic.parse("2006-08-20 03:30:30", :now => @time_2006_08_16_14_00_00)
0
+ assert_equal Time.local(2006, 8, 20, 3, 30, 30), time
0
+
0
+ time = Chronic.parse("2006-08-20 15:30:30", :now => @time_2006_08_16_14_00_00)
0
+ assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
0
+
0
+ time = Chronic.parse("2006-08-20 15:30.30", :now => @time_2006_08_16_14_00_00)
0
+ assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
0
+
0
     # rm_sd_rt
0
     
0
     #time = Chronic.parse("jan 5 13:00", :now => @time_2006_08_16_14_00_00)
0
@@ -183,8 +195,11 @@ class TestParsing < Test::Unit::TestCase
0
     time = Chronic.parse("4:00 in the morning", :now => @time_2006_08_16_14_00_00)
0
     assert_equal Time.local(2006, 8, 16, 4), time
0
     
0
- #time = Chronic.parse("november 4", :now => @time_2006_08_16_14_00_00)
0
- #assert_equal Time.local(2006, 11, 4, 12), time
0
+ time = Chronic.parse("november 4", :now => @time_2006_08_16_14_00_00)
0
+ assert_equal Time.local(2006, 11, 4, 12), time
0
+
0
+ time = Chronic.parse("aug 24", :now => @time_2006_08_16_14_00_00)
0
+ assert_equal Time.local(2006, 8, 24, 12), time
0
   end
0
   
0
   def test_parse_guess_rrr
0
@@ -392,7 +407,7 @@ class TestParsing < Test::Unit::TestCase
0
     # future
0
     
0
     time = Chronic.parse("3 years from now", :now => @time_2006_08_16_14_00_00)
0
- assert_equal Time.local(2009, 8, 16, 14, 30, 30), time
0
+ assert_equal Time.local(2009, 8, 16, 14, 0, 0), time
0
     
0
     time = Chronic.parse("6 months hence", :now => @time_2006_08_16_14_00_00)
0
     assert_equal Time.local(2007, 2, 16, 14, 30, 30), time
0
@@ -401,7 +416,7 @@ class TestParsing < Test::Unit::TestCase
0
     assert_equal Time.local(2006, 9, 27, 14, 30, 30), time
0
     
0
     time = Chronic.parse("1 week from now", :now => @time_2006_08_16_14_00_00)
0
- assert_equal Time.local(2006, 8, 23, 14, 30, 30), time
0
+ assert_equal Time.local(2006, 8, 23, 14, 0, 0), time
0
     
0
     time = Chronic.parse("1 day hence", :now => @time_2006_08_16_14_00_00)
0
     assert_equal Time.local(2006, 8, 17, 14), time

Comments

    No one has commented yet.