Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensures 31st parses correctly with day names

  • Loading branch information...
commit f50d4cd9aaa5ebcd5c214e79534b781a2372e775 1 parent e565e73
Joe Fiorini + Eric Hankinson authored
Showing with 39 additions and 3 deletions.
  1. +1 −0  .gitignore
  2. +17 −3 lib/chronic/handlers.rb
  3. +21 −0 test/test_parsing.rb
View
1  .gitignore
@@ -3,3 +3,4 @@ pkg
rdoc
.yardoc
doc
+tags
View
20 lib/chronic/handlers.rb
@@ -255,7 +255,7 @@ def handle_rdn_rmn_od(tokens, options)
begin
start_time = Chronic.time_class.local(year, month.index, day)
- end_time = Chronic.time_class.local(year, month.index, day + 1)
+ end_time = time_with_rollover(year, month.index, day + 1)
Span.new(start_time, end_time)
rescue ArgumentError
nil
@@ -272,7 +272,7 @@ def handle_rdn_rmn_sd(tokens, options)
begin
start_time = Chronic.time_class.local(year, month.index, day)
- end_time = Chronic.time_class.local(year, month.index, day + 1)
+ end_time = time_with_rollover(year, month.index, day + 1)
Span.new(start_time, end_time)
rescue ArgumentError
nil
@@ -289,7 +289,7 @@ def handle_rdn_rmn_sd_sy(tokens, options)
begin
start_time = Chronic.time_class.local(year, month.index, day)
- end_time = Chronic.time_class.local(year, month.index, day + 1)
+ end_time = time_with_rollover(year, month.index, day + 1)
Span.new(start_time, end_time)
rescue ArgumentError
nil
@@ -452,6 +452,20 @@ def find_within(tags, span, pointer)
end
end
+ def time_with_rollover(year, month, day)
+ date_parts =
+ if month_overflow?(year, month, day)
+ if month == 12
+ [year + 1, 1, 1]
+ else
+ [year, month + 1, 1]
+ end
+ else
+ [year, month, day]
+ end
+ Chronic.time_class.local(*date_parts)
+ end
+
def dealias_and_disambiguate_times(tokens, options)
# handle aliases of am/pm
# 5:00 in the morning -> 5:00 am
View
21 test/test_parsing.rb
@@ -926,16 +926,37 @@ def test_noon
def test_handle_rdn_rmn_sd
time = parse_now("Thu Aug 10")
assert_equal Time.local(2006, 8, 10, 12), time
+
+ time = parse_now("Thursday July 31")
+ assert_equal Time.local(2006, 7, 31, 12), time
+
+ time = parse_now("Thursday December 31")
+ assert_equal Time.local(2006, 12, 31, 12), time
end
def test_handle_rdn_rmn_sd_sy
time = parse_now("Thu Aug 10 2006")
assert_equal Time.local(2006, 8, 10, 12), time
+
+ time = parse_now("Thursday July 31 2006")
+ assert_equal Time.local(2006, 7, 31, 12), time
+
+ time = parse_now("Thursday December 31 2006")
+ assert_equal Time.local(2006, 12, 31, 12), time
+
+ time = parse_now("Thursday December 30 2006")
+ assert_equal Time.local(2006, 12, 30, 12), time
end
def test_handle_rdn_rmn_od
time = parse_now("Thu Aug 10th")
assert_equal Time.local(2006, 8, 10, 12), time
+
+ time = parse_now("Thursday July 31st")
+ assert_equal Time.local(2006, 7, 31, 12), time
+
+ time = parse_now("Thursday December 31st")
+ assert_equal Time.local(2006, 12, 31, 12), time
end
private
Please sign in to comment.
Something went wrong with that request. Please try again.