Permalink
Browse files

Merge branch 'master' into develop

  • Loading branch information...
2 parents 3d7203a + f2b6cfd commit c22f9b2c01d1d2e1089f55eacf3ca1666f5a8dd6 Lee Jarvis committed Sep 2, 2011
Showing with 32 additions and 2 deletions.
  1. +8 −0 HISTORY.md
  2. +1 −1 lib/chronic.rb
  3. +1 −0 lib/chronic/chronic.rb
  4. +10 −0 lib/chronic/handlers.rb
  5. +1 −1 lib/chronic/repeater.rb
  6. +11 −0 test/test_parsing.rb
View
@@ -1,3 +1,11 @@
+# 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
+
# 0.6.2 / 2011-07-28
* Ensure specific endian handlers are prioritised over normal date handlers
View
@@ -28,7 +28,7 @@
#
# @author Tom Preston-Werner, Lee Jarvis
module Chronic
- VERSION = "0.6.2"
+ VERSION = "0.6.3"
class << self
View
@@ -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)
],
View
@@ -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
View
@@ -58,7 +58,7 @@ def self.scan_for_day_names(token)
/^m[ou]n(day)?$/ => :monday,
/^t(ue|eu|oo|u|)s?(day)?$/ => :tuesday,
/^we(d|dnes|nds|nns)(day)?$/ => :wednesday,
- /^th(urs|ers)(day)?$/ => :thursday,
+ /^th(u(?:rs)?|ers)(day)?$/ => :thursday,
/^fr[iy](day)?$/ => :friday,
/^sat(t?[ue]rday)?$/ => :saturday,
/^su[nm](day)?$/ => :sunday
View
@@ -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

0 comments on commit c22f9b2

Please sign in to comment.