public this repo is viewable by everyone
Fork of mojombo/chronic
Description: "Chronic is a pure Ruby natural language date parser." + improvements, corrections, speedups, and additions
Homepage: http://chronic.rubyforge.org
Clone URL: git://github.com/jf/chronic.git
fixes, + tuning - ordinal.rb + scalar.rb
jf (author)
about 1 month ago
commit  0d25ff1f36314716305efa6398272e1e6ef1a055
tree    c5adb67abea1d3d8a5bec9ed0e058cd57116ebc6
parent  8a931393e9499795a5c53a8fb8208842643cb38b
...
19
20
21
22
 
23
24
25
...
37
38
39
40
41
 
...
19
20
21
 
22
23
24
25
...
37
38
39
 
40
41
0
@@ -19,7 +19,7 @@ module Chronic
0
     
0
     def self.scan_for_days(token)
0
       if token.word =~ /^(\d*)(st|nd|rd|th)$/
0
- unless $1.to_i > 31
1
+ unless $1.to_i > 31 && $1.to_i < 1
0
           return OrdinalDay.new(token.word.to_i)
0
         end
0
       end
0
@@ -37,4 +37,4 @@ module Chronic
0
     end
0
   end
0
 
0
-end
0
\ No newline at end of file
0
+end
...
23
24
25
26
27
 
 
 
28
29
30
...
32
33
34
35
36
 
 
 
37
38
39
...
41
42
43
44
 
45
46
47
...
71
72
73
74
75
 
...
23
24
25
 
 
26
27
28
29
30
31
...
33
34
35
 
 
36
37
38
39
40
41
...
43
44
45
 
46
47
48
49
...
73
74
75
 
76
77
0
@@ -23,8 +23,9 @@ module Chronic
0
     
0
     def self.scan_for_days(token, post_token)
0
       if token.word =~ /^\d\d?$/
0
- unless token.word.to_i > 31 || (post_token && %w{am pm morning afternoon evening night}.include?(post_token))
0
- return ScalarDay.new(token.word.to_i)
0
+ toi = token.word.to_i
0
+ unless toi > 31 || toi < 1 || (post_token && %w{am pm morning afternoon evening night}.include?(post_token.word))
0
+ return ScalarDay.new(toi)
0
         end
0
       end
0
       return nil
0
@@ -32,8 +33,9 @@ module Chronic
0
     
0
     def self.scan_for_months(token, post_token)
0
       if token.word =~ /^\d\d?$/
0
- unless token.word.to_i > 12 || (post_token && %w{am pm morning afternoon evening night}.include?(post_token))
0
- return ScalarMonth.new(token.word.to_i)
0
+ toi = token.word.to_i
0
+ unless toi > 12 || toi < 1 || (post_token && %w{am pm morning afternoon evening night}.include?(post_token.word))
0
+ return ScalarMonth.new(toi)
0
         end
0
       end
0
       return nil
0
@@ -41,7 +43,7 @@ module Chronic
0
     
0
     def self.scan_for_years(token, post_token)
0
       if token.word =~ /^([1-9]\d)?\d\d?$/
0
- unless post_token && %w{am pm morning afternoon evening night}.include?(post_token)
0
+ unless post_token && %w{am pm morning afternoon evening night}.include?(post_token.word)
0
           return ScalarYear.new(token.word.to_i)
0
         end
0
       end
0
@@ -71,4 +73,4 @@ module Chronic
0
     end
0
   end
0
 
0
-end
0
\ No newline at end of file
0
+end

Comments

  • technoweenie 23 days ago

    What’s the deal with this? "unless $1.to_i > 31 && $1.to_i < 1" Isn’t that impossible? Should there be tests with this?

  • pretty sure you meant: unless $1.to_i > 31 || $1.to_i < 1

  • jf 20 days ago

    aii!!! yep folks, you caught me on this one… thanks, JackDanger. Commit on the way…