chronic 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,29 @@
1
+ = 0.1.5 2006-12-20
2
+
3
+ * fixed 'aug 20' returning next year if current month is august
4
+ * modified behavior of 'from now'
5
+ * added support for seconds on times, and thus db timestamp format: "2006-12-20 18:04:23"
6
+ * made Hoe compliant
7
+
8
+ = 0.1.4
9
+
10
+ * removed verbose error checking code. oops. :-/
11
+
12
+ = 0.1.3
13
+
14
+ * improved regexes for word variations (Josh Goebel)
15
+ * fixed a bug that caused "today at 3am" to return nil if current time is after 3am
16
+
17
+ = 0.1.2
18
+
19
+ * removed Date dependency (now works on windows properly without fiddling)
20
+
21
+ = 0.1.1
22
+
23
+ * run to_s on incoming object
24
+ * fixed loop loading of repeaters files (out of order on some machines)
25
+ * fixed find_within to use this instead of next (was breaking "today at 6pm")
26
+
27
+ = 0.1.0
28
+
29
+ * initial release
data/Manifest.txt ADDED
@@ -0,0 +1,43 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/chronic.rb
6
+ lib/chronic/chronic.rb
7
+ lib/chronic/grabber.rb
8
+ lib/chronic/handlers.rb
9
+ lib/chronic/ordinal.rb
10
+ lib/chronic/pointer.rb
11
+ lib/chronic/repeater.rb
12
+ lib/chronic/repeaters/repeater_day.rb
13
+ lib/chronic/repeaters/repeater_day_name.rb
14
+ lib/chronic/repeaters/repeater_day_portion.rb
15
+ lib/chronic/repeaters/repeater_fortnight.rb
16
+ lib/chronic/repeaters/repeater_hour.rb
17
+ lib/chronic/repeaters/repeater_minute.rb
18
+ lib/chronic/repeaters/repeater_month.rb
19
+ lib/chronic/repeaters/repeater_month_name.rb
20
+ lib/chronic/repeaters/repeater_season.rb
21
+ lib/chronic/repeaters/repeater_season_name.rb
22
+ lib/chronic/repeaters/repeater_second.rb
23
+ lib/chronic/repeaters/repeater_time.rb
24
+ lib/chronic/repeaters/repeater_week.rb
25
+ lib/chronic/repeaters/repeater_weekend.rb
26
+ lib/chronic/repeaters/repeater_year.rb
27
+ lib/chronic/scalar.rb
28
+ lib/chronic/separator.rb
29
+ test/parse_numbers.rb
30
+ test/suite.rb
31
+ test/test_Chronic.rb
32
+ test/test_Handler.rb
33
+ test/test_RepeaterDayName.rb
34
+ test/test_RepeaterFortnight.rb
35
+ test/test_RepeaterHour.rb
36
+ test/test_RepeaterMonth.rb
37
+ test/test_RepeaterMonthName.rb
38
+ test/test_RepeaterTime.rb
39
+ test/test_RepeaterWeek.rb
40
+ test/test_RepeaterYear.rb
41
+ test/test_Span.rb
42
+ test/test_Token.rb
43
+ test/test_parsing.rb
@@ -1,14 +1,18 @@
1
- =Chronic
1
+ Chronic
2
+ http://chronic.rubyforge.org/
3
+ by Tom Preston-Werner
4
+
5
+ == DESCRIPTION:
2
6
 
3
7
  Chronic is a natural language date/time parser written in pure Ruby. See below for the wide variety of formats Chronic will parse.
4
8
 
5
- ==Installation
9
+ == INSTALLATION:
6
10
 
7
11
  Chronic can be installed via RubyGems:
8
12
 
9
13
  $ sudo gem install chronic
10
14
 
11
- ==Usage
15
+ == USAGE:
12
16
 
13
17
  You can parse strings containing a natural language date using the Chronic.parse method.
14
18
 
@@ -39,7 +43,7 @@ You can parse strings containing a natural language date using the Chronic.parse
39
43
 
40
44
  See Chronic.parse for detailed usage instructions.
41
45
 
42
- ==Examples
46
+ == EXAMPLES:
43
47
 
44
48
  Chronic can parse a huge variety of date and time formats. Following is a small sample of strings that will be properly parsed. Parsing is case insensitive and will handle common abbreviations and misspellings.
45
49
 
@@ -110,11 +114,36 @@ Specific Dates
110
114
  Specific Times (many of the above with an added time)
111
115
 
112
116
  January 5 at 7pm
113
- 1979-05-27 05:00
117
+ 1979-05-27 05:00:00
114
118
  etc
115
119
 
116
- ==Limitations
120
+ == LIMITATIONS:
117
121
 
118
122
  Chronic uses Ruby's built in Time class for all time storage and computation. Because of this, only times that the Time class can handle will be properly parsed. Parsing for times outside of this range will simply return nil. Support for a wider range of times is planned for a future release.
119
123
 
120
- Time zones other than the local one are not currently supported. Support for other time zones is planned for a future release.
124
+ Time zones other than the local one are not currently supported. Support for other time zones is planned for a future release.
125
+
126
+ == LICENSE:
127
+
128
+ (The MIT License)
129
+
130
+ Copyright (c) 2006 Ryan Davis, Zen Spider Software
131
+
132
+ Permission is hereby granted, free of charge, to any person obtaining
133
+ a copy of this software and associated documentation files (the
134
+ "Software"), to deal in the Software without restriction, including
135
+ without limitation the rights to use, copy, modify, merge, publish,
136
+ distribute, sublicense, and/or sell copies of the Software, and to
137
+ permit persons to whom the Software is furnished to do so, subject to
138
+ the following conditions:
139
+
140
+ The above copyright notice and this permission notice shall be
141
+ included in all copies or substantial portions of the Software.
142
+
143
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
144
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
145
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
146
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
147
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
148
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
149
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/chronic.rb'
6
+
7
+ Hoe.new('chronic', Chronic::VERSION) do |p|
8
+ p.rubyforge_name = 'chronic'
9
+ p.summary = 'A natural language date parser'
10
+ p.description = p.paragraphs_of('README.txt', 2).join("\n\n")
11
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
12
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
13
+ end
14
+
15
+ # vim: syntax=Ruby
16
+
17
+ __END__
18
+
19
+ require 'rubygems'
20
+
21
+ SPEC = Gem::Specification.new do |s|
22
+ s.name = 'chronic'
23
+ s.version = '0.1.5'
24
+ s.author = 'Tom Preston-Werner'
25
+ s.email = 'tom@rubyisawesome.com'
26
+ s.homepage = 'http://chronic.rubyforge.org'
27
+ s.platform = Gem::Platform::RUBY
28
+ s.summary = "A natural language date parser"
29
+ candidates = Dir["{lib,test}/**/*"]
30
+ s.files = candidates.delete_if do |item|
31
+ item.include?('.svn')
32
+ end
33
+ s.require_path = "lib"
34
+ s.autorequire = "chronic"
35
+ s.test_file = "test/suite.rb"
36
+ s.has_rdoc = true
37
+ s.extra_rdoc_files = ['README']
38
+ s.rdoc_options << '--main' << 'README'
39
+ end
data/lib/chronic.rb CHANGED
@@ -34,6 +34,14 @@ require 'chronic/ordinal'
34
34
  require 'chronic/separator'
35
35
 
36
36
  module Chronic
37
+ VERSION = "0.1.5"
38
+
37
39
  def self.debug; false; end
38
40
  end
39
41
 
42
+ alias p_orig p
43
+
44
+ def p(val)
45
+ p_orig val
46
+ puts
47
+ end
@@ -108,7 +108,6 @@ module Chronic
108
108
  normalized_text.gsub!(/\byesterday\b/, 'last day')
109
109
  normalized_text.gsub!(/\bnoon\b/, '12:00')
110
110
  normalized_text.gsub!(/\bmidnight\b/, '24:00')
111
- normalized_text.gsub!(/\bfrom now\b/, 'future')
112
111
  normalized_text.gsub!(/\bbefore now\b/, 'past')
113
112
  normalized_text.gsub!(/\bnow\b/, 'this second')
114
113
  normalized_text.gsub!(/\b(ago|before)\b/, 'past')
@@ -88,7 +88,7 @@ module Chronic
88
88
 
89
89
  def handle_m_d(month, day, time_tokens, options) #:nodoc:
90
90
  month.start = @now
91
- span = month.next(options[:context])
91
+ span = month.this(options[:context])
92
92
 
93
93
  day_start = Time.local(span.begin.year, span.begin.month, day)
94
94
 
@@ -213,7 +213,7 @@ module Chronic
213
213
 
214
214
  def handle_s_r_p(tokens, options) #:nodoc:
215
215
  repeater = tokens[1].get_tag(Repeater)
216
-
216
+
217
217
  span =
218
218
  case true
219
219
  when [RepeaterYear, RepeaterSeason, RepeaterSeasonName, RepeaterMonth, RepeaterMonthName, RepeaterFortnight, RepeaterWeek].include?(repeater.class)
@@ -60,7 +60,7 @@ class Chronic::Repeater < Chronic::Tag #:nodoc:
60
60
  end
61
61
 
62
62
  def self.scan_for_times(token, options)
63
- if token.word =~ /^\d{1,2}(:?\d{2})?$/
63
+ if token.word =~ /^\d{1,2}(:?\d{2})?([\.:]?\d{2})?$/
64
64
  return Chronic::RepeaterTime.new(token.word, options)
65
65
  end
66
66
  return nil
@@ -99,7 +99,7 @@ class Chronic::Repeater < Chronic::Tag #:nodoc:
99
99
  # returns the next occurance of this repeatable.
100
100
  def next(pointer)
101
101
  !@now.nil? || raise("Start point must be set before calling #next")
102
- [:future, :past].include?(pointer) || raise("First argument 'pointer' must be one of :past or :future")
102
+ [:future, :none, :past].include?(pointer) || raise("First argument 'pointer' must be one of :past or :future")
103
103
  #raise("Repeatable#next must be overridden in subclasses")
104
104
  end
105
105
 
@@ -13,6 +13,12 @@ class Chronic::RepeaterMonthName < Chronic::Repeater #:nodoc:
13
13
  else @now.month > target_month
14
14
  @current_month_begin = Time.local(@now.year + 1, target_month)
15
15
  end
16
+ when :none
17
+ if @now.month <= target_month
18
+ @current_month_begin = Time.local(@now.year, target_month)
19
+ else @now.month > target_month
20
+ @current_month_begin = Time.local(@now.year + 1, target_month)
21
+ end
16
22
  when :past
17
23
  if @now.month > target_month
18
24
  @current_month_begin = Time.local(@now.year, target_month)
@@ -47,9 +53,12 @@ class Chronic::RepeaterMonthName < Chronic::Repeater #:nodoc:
47
53
  def this(pointer = :future)
48
54
  super
49
55
 
50
- pointer = :future if pointer == :none
51
-
52
- self.next(pointer)
56
+ case pointer
57
+ when :past
58
+ self.next(pointer)
59
+ when :future, :none
60
+ self.next(:none)
61
+ end
53
62
  end
54
63
 
55
64
  def width
@@ -25,7 +25,7 @@ class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
25
25
  end
26
26
 
27
27
  def initialize(time, options = {})
28
- t = time.sub(/\:/, '')
28
+ t = time.gsub(/\:/, '')
29
29
  @type =
30
30
  if (1..2) === t.size
31
31
  Tick.new(t.to_i * 60 * 60, true)
@@ -34,8 +34,13 @@ class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
34
34
  elsif t.size == 4
35
35
  ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
36
36
  Tick.new(t[0..1].to_i * 60 * 60 + t[2..3].to_i * 60, ambiguous)
37
+ elsif t.size == 5
38
+ Tick.new(t[0..0].to_i * 60 * 60 + t[1..2].to_i * 60 + t[3..4].to_i, true)
39
+ elsif t.size == 6
40
+ ambiguous = time =~ /:/ && t[0..0].to_i != 0 && t[0..1].to_i <= 12
41
+ Tick.new(t[0..1].to_i * 60 * 60 + t[2..3].to_i * 60 + t[4..5].to_i, ambiguous)
37
42
  else
38
- raise("Time cannot exceed four digits")
43
+ raise("Time cannot exceed six digits")
39
44
  end
40
45
  end
41
46
 
data/test/test_parsing.rb CHANGED
@@ -24,6 +24,9 @@ class TestParsing < Test::Unit::TestCase
24
24
  time = Chronic.parse("may 28 at 5pm", :now => @time_2006_08_16_14_00_00, :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)
28
+ assert_equal Time.local(2006, 5, 28, 17, 32, 19), time
29
+
27
30
  # rm_od
28
31
 
29
32
  time = Chronic.parse("may 27th", :now => @time_2006_08_16_14_00_00)
@@ -124,6 +127,15 @@ class TestParsing < Test::Unit::TestCase
124
127
  time = Chronic.parse("2006-08-20 03:00", :now => @time_2006_08_16_14_00_00)
125
128
  assert_equal Time.local(2006, 8, 20, 3), time
126
129
 
130
+ time = Chronic.parse("2006-08-20 03:30:30", :now => @time_2006_08_16_14_00_00)
131
+ assert_equal Time.local(2006, 8, 20, 3, 30, 30), time
132
+
133
+ time = Chronic.parse("2006-08-20 15:30:30", :now => @time_2006_08_16_14_00_00)
134
+ assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
135
+
136
+ time = Chronic.parse("2006-08-20 15:30.30", :now => @time_2006_08_16_14_00_00)
137
+ assert_equal Time.local(2006, 8, 20, 15, 30, 30), time
138
+
127
139
  # rm_sd_rt
128
140
 
129
141
  #time = Chronic.parse("jan 5 13:00", :now => @time_2006_08_16_14_00_00)
@@ -183,8 +195,11 @@ class TestParsing < Test::Unit::TestCase
183
195
  time = Chronic.parse("4:00 in the morning", :now => @time_2006_08_16_14_00_00)
184
196
  assert_equal Time.local(2006, 8, 16, 4), time
185
197
 
186
- #time = Chronic.parse("november 4", :now => @time_2006_08_16_14_00_00)
187
- #assert_equal Time.local(2006, 11, 4, 12), time
198
+ time = Chronic.parse("november 4", :now => @time_2006_08_16_14_00_00)
199
+ assert_equal Time.local(2006, 11, 4, 12), time
200
+
201
+ time = Chronic.parse("aug 24", :now => @time_2006_08_16_14_00_00)
202
+ assert_equal Time.local(2006, 8, 24, 12), time
188
203
  end
189
204
 
190
205
  def test_parse_guess_rrr
@@ -392,7 +407,7 @@ class TestParsing < Test::Unit::TestCase
392
407
  # future
393
408
 
394
409
  time = Chronic.parse("3 years from now", :now => @time_2006_08_16_14_00_00)
395
- assert_equal Time.local(2009, 8, 16, 14, 30, 30), time
410
+ assert_equal Time.local(2009, 8, 16, 14, 0, 0), time
396
411
 
397
412
  time = Chronic.parse("6 months hence", :now => @time_2006_08_16_14_00_00)
398
413
  assert_equal Time.local(2007, 2, 16, 14, 30, 30), time
@@ -401,7 +416,7 @@ class TestParsing < Test::Unit::TestCase
401
416
  assert_equal Time.local(2006, 9, 27, 14, 30, 30), time
402
417
 
403
418
  time = Chronic.parse("1 week from now", :now => @time_2006_08_16_14_00_00)
404
- assert_equal Time.local(2006, 8, 23, 14, 30, 30), time
419
+ assert_equal Time.local(2006, 8, 23, 14, 0, 0), time
405
420
 
406
421
  time = Chronic.parse("1 day hence", :now => @time_2006_08_16_14_00_00)
407
422
  assert_equal Time.local(2006, 8, 17, 14), time
metadata CHANGED
@@ -3,16 +3,16 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: chronic
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.4
7
- date: 2006-10-20 00:00:00 -07:00
6
+ version: 0.1.5
7
+ date: 2006-12-21 00:00:00 -08:00
8
8
  summary: A natural language date parser
9
9
  require_paths:
10
10
  - lib
11
- email: tom@rubyisawesome.com
12
- homepage: http://chronic.rubyforge.org
13
- rubyforge_project:
14
- description:
15
- autorequire: chronic
11
+ email: ryand-ruby@zenspider.com
12
+ homepage: "\thttp://chronic.rubyforge.org/"
13
+ rubyforge_project: chronic
14
+ description: Chronic is a natural language date/time parser written in pure Ruby. See below for the wide variety of formats Chronic will parse.
15
+ autorequire:
16
16
  default_executable:
17
17
  bindir: bin
18
18
  has_rdoc: true
@@ -26,9 +26,12 @@ platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
28
  authors:
29
- - Tom Preston-Werner
29
+ - Ryan Davis
30
30
  files:
31
- - lib/chronic
31
+ - History.txt
32
+ - Manifest.txt
33
+ - README.txt
34
+ - Rakefile
32
35
  - lib/chronic.rb
33
36
  - lib/chronic/chronic.rb
34
37
  - lib/chronic/grabber.rb
@@ -36,9 +39,6 @@ files:
36
39
  - lib/chronic/ordinal.rb
37
40
  - lib/chronic/pointer.rb
38
41
  - lib/chronic/repeater.rb
39
- - lib/chronic/repeaters
40
- - lib/chronic/scalar.rb
41
- - lib/chronic/separator.rb
42
42
  - lib/chronic/repeaters/repeater_day.rb
43
43
  - lib/chronic/repeaters/repeater_day_name.rb
44
44
  - lib/chronic/repeaters/repeater_day_portion.rb
@@ -54,11 +54,12 @@ files:
54
54
  - lib/chronic/repeaters/repeater_week.rb
55
55
  - lib/chronic/repeaters/repeater_weekend.rb
56
56
  - lib/chronic/repeaters/repeater_year.rb
57
+ - lib/chronic/scalar.rb
58
+ - lib/chronic/separator.rb
57
59
  - test/parse_numbers.rb
58
60
  - test/suite.rb
59
61
  - test/test_Chronic.rb
60
62
  - test/test_Handler.rb
61
- - test/test_parsing.rb
62
63
  - test/test_RepeaterDayName.rb
63
64
  - test/test_RepeaterFortnight.rb
64
65
  - test/test_RepeaterHour.rb
@@ -69,19 +70,38 @@ files:
69
70
  - test/test_RepeaterYear.rb
70
71
  - test/test_Span.rb
71
72
  - test/test_Token.rb
72
- - README
73
+ - test/test_parsing.rb
73
74
  test_files:
74
- - test/suite.rb
75
- rdoc_options:
76
- - --main
77
- - README
78
- extra_rdoc_files:
79
- - README
75
+ - test/test_Chronic.rb
76
+ - test/test_Handler.rb
77
+ - test/test_parsing.rb
78
+ - test/test_RepeaterDayName.rb
79
+ - test/test_RepeaterFortnight.rb
80
+ - test/test_RepeaterHour.rb
81
+ - test/test_RepeaterMonth.rb
82
+ - test/test_RepeaterMonthName.rb
83
+ - test/test_RepeaterTime.rb
84
+ - test/test_RepeaterWeek.rb
85
+ - test/test_RepeaterYear.rb
86
+ - test/test_Span.rb
87
+ - test/test_Token.rb
88
+ rdoc_options: []
89
+
90
+ extra_rdoc_files: []
91
+
80
92
  executables: []
81
93
 
82
94
  extensions: []
83
95
 
84
96
  requirements: []
85
97
 
86
- dependencies: []
87
-
98
+ dependencies:
99
+ - !ruby/object:Gem::Dependency
100
+ name: hoe
101
+ version_requirement:
102
+ version_requirements: !ruby/object:Gem::Version::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 1.1.6
107
+ version: