chronic 0.6.6 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ pkg
3
3
  rdoc
4
4
  .yardoc
5
5
  doc
6
+ tags
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.6.7 / 2012-01-31
2
+
3
+ * Handle day, month names with scalar day and year (Joe Fiorini)
4
+ * Ensure 31st parses correctly with day names (Joe Fiorini)
5
+
1
6
  # 0.6.6 / 2011-11-23
2
7
 
3
8
  * `Chronic.parse('thur')` no longer returns `nil` (@harold)
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.6"
31
+ VERSION = "0.6.7"
32
32
 
33
33
  class << self
34
34
 
@@ -170,6 +170,7 @@ module Chronic
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
172
  Handler.new([:repeater_day_name, :repeater_month_name, :scalar_day], :handle_rdn_rmn_sd),
173
+ Handler.new([:repeater_day_name, :repeater_month_name, :scalar_day, :scalar_year], :handle_rdn_rmn_sd_sy),
173
174
  Handler.new([:repeater_day_name, :repeater_month_name, :ordinal_day], :handle_rdn_rmn_od),
174
175
  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),
175
176
  Handler.new([:repeater_month_name, :scalar_day, :scalar_year], :handle_rmn_sd_sy),
@@ -255,7 +255,7 @@ module Chronic
255
255
 
256
256
  begin
257
257
  start_time = Chronic.time_class.local(year, month.index, day)
258
- end_time = Chronic.time_class.local(year, month.index, day + 1)
258
+ end_time = time_with_rollover(year, month.index, day + 1)
259
259
  Span.new(start_time, end_time)
260
260
  rescue ArgumentError
261
261
  nil
@@ -272,7 +272,24 @@ module Chronic
272
272
 
273
273
  begin
274
274
  start_time = Chronic.time_class.local(year, month.index, day)
275
- end_time = Chronic.time_class.local(year, month.index, day + 1)
275
+ end_time = time_with_rollover(year, month.index, day + 1)
276
+ Span.new(start_time, end_time)
277
+ rescue ArgumentError
278
+ nil
279
+ end
280
+ end
281
+
282
+ # Handle RepeaterDayName RepeaterMonthName ScalarDay ScalarYear
283
+ def handle_rdn_rmn_sd_sy(tokens, options)
284
+ month = tokens[1].get_tag(RepeaterMonthName)
285
+ day = tokens[2].get_tag(ScalarDay).type
286
+ year = tokens[3].get_tag(ScalarYear).type
287
+
288
+ return if month_overflow?(year, month.index, day)
289
+
290
+ begin
291
+ start_time = Chronic.time_class.local(year, month.index, day)
292
+ end_time = time_with_rollover(year, month.index, day + 1)
276
293
  Span.new(start_time, end_time)
277
294
  rescue ArgumentError
278
295
  nil
@@ -435,6 +452,20 @@ module Chronic
435
452
  end
436
453
  end
437
454
 
455
+ def time_with_rollover(year, month, day)
456
+ date_parts =
457
+ if month_overflow?(year, month, day)
458
+ if month == 12
459
+ [year + 1, 1, 1]
460
+ else
461
+ [year, month + 1, 1]
462
+ end
463
+ else
464
+ [year, month, day]
465
+ end
466
+ Chronic.time_class.local(*date_parts)
467
+ end
468
+
438
469
  def dealias_and_disambiguate_times(tokens, options)
439
470
  # handle aliases of am/pm
440
471
  # 5:00 in the morning -> 5:00 am
data/test/test_parsing.rb CHANGED
@@ -926,11 +926,37 @@ class TestParsing < Test::Unit::TestCase
926
926
  def test_handle_rdn_rmn_sd
927
927
  time = parse_now("Thu Aug 10")
928
928
  assert_equal Time.local(2006, 8, 10, 12), time
929
+
930
+ time = parse_now("Thursday July 31")
931
+ assert_equal Time.local(2006, 7, 31, 12), time
932
+
933
+ time = parse_now("Thursday December 31")
934
+ assert_equal Time.local(2006, 12, 31, 12), time
935
+ end
936
+
937
+ def test_handle_rdn_rmn_sd_sy
938
+ time = parse_now("Thu Aug 10 2006")
939
+ assert_equal Time.local(2006, 8, 10, 12), time
940
+
941
+ time = parse_now("Thursday July 31 2006")
942
+ assert_equal Time.local(2006, 7, 31, 12), time
943
+
944
+ time = parse_now("Thursday December 31 2006")
945
+ assert_equal Time.local(2006, 12, 31, 12), time
946
+
947
+ time = parse_now("Thursday December 30 2006")
948
+ assert_equal Time.local(2006, 12, 30, 12), time
929
949
  end
930
950
 
931
951
  def test_handle_rdn_rmn_od
932
952
  time = parse_now("Thu Aug 10th")
933
953
  assert_equal Time.local(2006, 8, 10, 12), time
954
+
955
+ time = parse_now("Thursday July 31st")
956
+ assert_equal Time.local(2006, 7, 31, 12), time
957
+
958
+ time = parse_now("Thursday December 31st")
959
+ assert_equal Time.local(2006, 12, 31, 12), time
934
960
  end
935
961
 
936
962
  private
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.6
4
+ version: 0.6.7
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-11-23 00:00:00.000000000Z
13
+ date: 2012-02-01 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Chronic is a natural language date/time parser written in pure Ruby.
16
16
  email: