Skip to content

Commit

Permalink
handle scalar days with month names as well as ordinals
Browse files Browse the repository at this point in the history
closes mojombo#61
  • Loading branch information
Lee Jarvis committed Sep 2, 2011
1 parent e0ffefe commit f2b6cfd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
@@ -1,3 +1,7 @@
# HEAD

* Add the ability to handle scalar-day/repeater-month-name as well as ordinals

# 0.6.3 / 2011-08-01

* Ensure 'thu' is parsed as Thursday for 1.8.7 generic timestamp
Expand Down
1 change: 1 addition & 0 deletions lib/chronic/chronic.rb
Expand Up @@ -182,6 +182,7 @@ def definitions(options={})
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),
Handler.new([:scalar_day, :repeater_month_name, :separator_at?, 'time?'], :handle_sd_rmn),
Handler.new([:scalar_year, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_day, :separator_at?, 'time?'], :handle_sy_sm_sd),
Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_year], :handle_sm_sy)
],
Expand Down
10 changes: 10 additions & 0 deletions lib/chronic/handlers.rb
Expand Up @@ -59,6 +59,16 @@ def handle_od_rmn(tokens, options)
handle_m_d(month, day, tokens[2..tokens.size], options)
end

# Handle scalar-day/repeater-month-name
def handle_sd_rmn(tokens, options)
month = tokens[1].get_tag(RepeaterMonthName)
day = tokens[0].get_tag(ScalarDay).type

return if month_overflow?(Chronic.now.year, month.index, day)

handle_m_d(month, day, tokens[2..tokens.size], options)
end

# Handle repeater-month-name/ordinal-day with separator-on
def handle_rmn_od_on(tokens, options)
if tokens.size > 3
Expand Down
11 changes: 11 additions & 0 deletions test/test_parsing.rb
Expand Up @@ -76,6 +76,17 @@ def test_handle_od_rmn
assert_equal Time.local(2006, 12, 11, 8), time
end

def test_handle_sd_rmn
time = parse_now("22 February")
assert_equal Time.local(2007, 2, 22, 12), time

time = parse_now("31 of may at 6:30pm")
assert_equal Time.local(2007, 5, 31, 18, 30), time

time = parse_now("11 december 8am")
assert_equal Time.local(2006, 12, 11, 8), time
end

def test_handle_rmn_od_on
time = parse_now("5:00 pm may 27th", :context => :past)
assert_equal Time.local(2006, 5, 27, 17), time
Expand Down

0 comments on commit f2b6cfd

Please sign in to comment.