Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added support for ordinal-day/repeater-month-name with optional time

27th of February
14th december at 4:15pm
  • Loading branch information...
commit 152124b4fcf62cd57a420fd5d4267cf330299ee1 1 parent 61e391b
Lee Jarvis authored
View
2  HISTORY.md
@@ -1,5 +1,7 @@
# TBA
+* Added support for parsing ordinal-dates and month names, ie:
+ `22nd of February at 6:30pm`
* Fix `Time.construct` leap year checking. Instead use `Date.leap?(year)`
# 0.4.4
View
2  README.md
@@ -102,6 +102,7 @@ Complex
Specific Dates
* January 5
+* 22nd of june
* February twenty first
* dec 25
* may 27th
@@ -125,6 +126,7 @@ Specific Dates
Specific Times (many of the above with an added time)
* January 5 at 7pm
+* 22nd of june at 8am
* 1979-05-27 05:00:00
* etc
View
1  lib/chronic/chronic.rb
@@ -180,6 +180,7 @@ def definitions(options={})
Handler.new([:repeater_month_name, :scalar_day, :separator_at?, 'time?'], :handle_rmn_sd),
Handler.new([:repeater_time, :repeater_day_portion?, :separator_on?, :repeater_month_name, :scalar_day], :handle_rmn_sd_on),
Handler.new([:repeater_month_name, :ordinal_day, :separator_at?, 'time?'], :handle_rmn_od),
+ Handler.new([:ordinal_day, :repeater_month_name, :separator_at?, 'time?'], :handle_od_rmn),
Handler.new([:repeater_time, :repeater_day_portion?, :separator_on?, :repeater_month_name, :ordinal_day], :handle_rmn_od_on),
Handler.new([:repeater_month_name, :scalar_year], :handle_rmn_sy),
Handler.new([:scalar_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_sd_rmn_sy),
View
5 lib/chronic/handlers.rb
@@ -31,6 +31,11 @@ def handle_rmn_od(tokens, options) #:nodoc:
handle_m_d(tokens[0].get_tag(RepeaterMonthName), tokens[1].get_tag(OrdinalDay).type, tokens[2..tokens.size], options)
end
+ # Handle ordinal-day/repeater-month-name
+ def handle_od_rmn(tokens, options) #:nodoc:
+ handle_m_d(tokens[1].get_tag(RepeaterMonthName), tokens[0].get_tag(OrdinalDay).type, tokens[2..tokens.size], options)
+ end
+
# Handle repeater-month-name/ordinal-day with separator-on
def handle_rmn_od_on(tokens, options) #:nodoc:
if tokens.size > 3
View
12 test/test_parsing.rb
@@ -244,6 +244,18 @@ def test_parse_guess_dates
assert_equal Time.local(1902, 8, 20, 12, 0, 0), time
end
+ # handle_od_rmn
+ def test_parse_od_rmn
+ time = parse_now("22nd February")
+ assert_equal Time.local(2007, 2, 22, 12), time
+
+ time = parse_now("31st of may at 6:30pm")
+ assert_equal Time.local(2007, 5, 31, 18, 30), time
+
+ time = parse_now("11th december 8am")
+ assert_equal Time.local(2006, 12, 11, 8), time
+ end
+
def test_parse_two_digit_years
time = parse_now("may 97")
assert_equal Time.local(1997, 5, 16, 12), time
Please sign in to comment.
Something went wrong with that request. Please try again.