chronic 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.6.5 / 2011-11-04
2
+
3
+ * Fix bug when parsing ordinal repeaters (#73)
4
+ * Added handler support for day_name month_name (@imme5150)
5
+ * Fix bug when parsing strings prefixed with PM
6
+
1
7
  # 0.6.4 / 2011-08-08
2
8
 
3
9
  * Fixed bug where 'noon' was parsed as 00:00 rather than 12:00
data/README.md CHANGED
@@ -162,14 +162,13 @@ If you'd like to hack on Chronic, start by forking the repo on GitHub:
162
162
 
163
163
  https://github.com/mojombo/chronic
164
164
 
165
- To get all of the dependencies, install the gem first. The best way to get
166
- your changes merged back into core is as follows:
165
+ The best way to get your changes merged back into core is as follows:
167
166
 
168
167
  1. Clone down your fork
169
168
  1. Create a thoughtfully named topic branch to contain your change
170
169
  1. Hack away
171
170
  1. Add tests and make sure everything still passes by running `rake`
172
- 1. Ensure your tests pass in multiple timezones
171
+ 1. Ensure your tests pass in multiple timezones. ie `TZ=utc rake` `TZ=BST rake`
173
172
  1. If you are adding new functionality, document it in the README
174
173
  1. Do not change the version number, we will do that on our end
175
174
  1. If necessary, rebase your commits into logical chunks, without errors
data/lib/chronic.rb CHANGED
@@ -28,7 +28,7 @@ require 'date'
28
28
  #
29
29
  # @author Tom Preston-Werner, Lee Jarvis
30
30
  module Chronic
31
- VERSION = "0.6.4"
31
+ VERSION = "0.6.5"
32
32
 
33
33
  class << self
34
34
 
@@ -114,7 +114,7 @@ module Chronic
114
114
  text = Numerizer.numerize(text)
115
115
  text.gsub!(/ \-(\d{4})\b/, ' tzminus\1')
116
116
  text.gsub!(/([\/\-\,\@])/) { ' ' + $1 + ' ' }
117
- text.gsub!(/\b0(\d+:\d+\s*pm?\b)/, '\1')
117
+ text.gsub!(/(?:^|\s)0(\d+:\d+\s*pm?\b)/, '\1')
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')
@@ -169,6 +169,8 @@ module Chronic
169
169
 
170
170
  :date => [
171
171
  Handler.new([:repeater_day_name, :repeater_month_name, :scalar_day, :repeater_time, :separator_slash_or_dash?, :time_zone, :scalar_year], :handle_rdn_rmn_sd_t_tz_sy),
172
+ Handler.new([:repeater_day_name, :repeater_month_name, :scalar_day], :handle_rdn_rmn_sd),
173
+ Handler.new([:repeater_day_name, :repeater_month_name, :ordinal_day], :handle_rdn_rmn_od),
172
174
  Handler.new([:scalar_year, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_day, :repeater_time, :time_zone], :handle_sy_sm_sd_t_tz),
173
175
  Handler.new([:repeater_month_name, :scalar_day, :scalar_year], :handle_rmn_sd_sy),
174
176
  Handler.new([:repeater_month_name, :ordinal_day, :scalar_year], :handle_rmn_od_sy),
@@ -245,6 +245,40 @@ module Chronic
245
245
  end
246
246
  end
247
247
 
248
+ # Handle RepeaterDayName RepeaterMonthName OrdinalDay
249
+ def handle_rdn_rmn_od(tokens, options)
250
+ month = tokens[1].get_tag(RepeaterMonthName)
251
+ day = tokens[2].get_tag(OrdinalDay).type
252
+ year = Chronic.now.year
253
+
254
+ return if month_overflow?(year, month.index, day)
255
+
256
+ begin
257
+ start_time = Chronic.time_class.local(year, month.index, day)
258
+ end_time = Chronic.time_class.local(year, month.index, day + 1)
259
+ Span.new(start_time, end_time)
260
+ rescue ArgumentError
261
+ nil
262
+ end
263
+ end
264
+
265
+ # Handle RepeaterDayName RepeaterMonthName ScalarDay
266
+ def handle_rdn_rmn_sd(tokens, options)
267
+ month = tokens[1].get_tag(RepeaterMonthName)
268
+ day = tokens[2].get_tag(ScalarDay).type
269
+ year = Chronic.now.year
270
+
271
+ return if month_overflow?(year, month.index, day)
272
+
273
+ begin
274
+ start_time = Chronic.time_class.local(year, month.index, day)
275
+ end_time = Chronic.time_class.local(year, month.index, day + 1)
276
+ Span.new(start_time, end_time)
277
+ rescue ArgumentError
278
+ nil
279
+ end
280
+ end
281
+
248
282
  # anchors
249
283
 
250
284
  # Handle repeaters
@@ -302,7 +336,7 @@ module Chronic
302
336
  ordinal.times do
303
337
  span = repeater.next(:future)
304
338
 
305
- if span.begin > outer_span.end
339
+ if span.begin >= outer_span.end
306
340
  span = nil
307
341
  break
308
342
  end
data/test/test_parsing.rb CHANGED
@@ -238,6 +238,9 @@ class TestParsing < Test::Unit::TestCase
238
238
  time = parse_now("7/12/11", :endian_precedence => :little)
239
239
  assert_equal Time.local(2011, 12, 7, 12), time
240
240
 
241
+ time = parse_now("9/19/2011 6:05:57 PM")
242
+ assert_equal Time.local(2011, 9, 19, 18, 05, 57), time
243
+
241
244
  # month day overflows
242
245
  time = parse_now("30/2/2000")
243
246
  assert_nil time
@@ -307,6 +310,19 @@ class TestParsing < Test::Unit::TestCase
307
310
  end
308
311
 
309
312
  def test_handle_orr
313
+ time = parse_now("5th tuesday in january")
314
+ assert_equal Time.local(2007, 01, 30, 12), time
315
+
316
+ time = parse_now("5th tuesday in february")
317
+ assert_equal nil, time
318
+
319
+ %W(jan feb march april may june july aug sep oct nov dec).each_with_index do |month, index|
320
+ time = parse_now("5th tuesday in #{month}")
321
+
322
+ if time then
323
+ assert_equal time.month, index+1
324
+ end
325
+ end
310
326
  end
311
327
 
312
328
  def test_handle_o_r_s_r
@@ -879,6 +895,16 @@ class TestParsing < Test::Unit::TestCase
879
895
  assert_equal Time.local(2011, 1, 1, 12, 0), t1
880
896
  end
881
897
 
898
+ def test_handle_rdn_rmn_sd
899
+ time = parse_now("Thu Aug 10")
900
+ assert_equal Time.local(2006, 8, 10, 12), time
901
+ end
902
+
903
+ def test_handle_rdn_rmn_od
904
+ time = parse_now("Thu Aug 10th")
905
+ assert_equal Time.local(2006, 8, 10, 12), time
906
+ end
907
+
882
908
  private
883
909
  def parse_now(string, options={})
884
910
  Chronic.parse(string, {:now => TIME_2006_08_16_14_00_00 }.merge(options))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-09 00:00:00.000000000Z
13
+ date: 2011-11-05 00:00:00.000000000Z
14
14
  dependencies: []
15
15
  description: Chronic is a natural language date/time parser written in pure Ruby.
16
16
  email:
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project: chronic
109
- rubygems_version: 1.8.6
109
+ rubygems_version: 1.8.11
110
110
  signing_key:
111
111
  specification_version: 3
112
112
  summary: Natural language date/time parsing.