lib/chronic/handlers.rb in chronic-0.9.1 vs lib/chronic/handlers.rb in chronic-0.10.0

- old
+ new

@@ -132,10 +132,12 @@ # Handle generic timestamp (ruby 1.8) def handle_generic(tokens, options) t = Chronic.time_class.parse(options[:text]) Span.new(t, t + 1) + rescue ArgumentError => e + raise e unless e.message =~ /out of range/ end # Handle repeater-month-name/scalar-day/scalar-year def handle_rmn_sd_sy(tokens, options) month = tokens[0].get_tag(RepeaterMonthName).index @@ -302,10 +304,27 @@ rescue ArgumentError nil end end + # Handle RepeaterDayName RepeaterMonthName OrdinalDay ScalarYear + def handle_rdn_rmn_od_sy(tokens, options) + month = tokens[1].get_tag(RepeaterMonthName) + day = tokens[2].get_tag(OrdinalDay).type + year = tokens[3].get_tag(ScalarYear).type + + return if month_overflow?(year, month.index, day) + + begin + start_time = Chronic.time_class.local(year, month.index, day) + end_time = time_with_rollover(year, month.index, day + 1) + Span.new(start_time, end_time) + rescue ArgumentError + nil + end + end + # Handle RepeaterDayName OrdinalDay def handle_rdn_od(tokens, options) day = tokens[1].get_tag(OrdinalDay).type time_tokens = tokens.last(tokens.size - 2) year = self.now.year @@ -474,13 +493,13 @@ # support methods def day_or_time(day_start, time_tokens, options) outer_span = Span.new(day_start, day_start + (24 * 60 * 60)) - if !time_tokens.empty? + unless time_tokens.empty? self.now = outer_span.begin - get_anchor(dealias_and_disambiguate_times(time_tokens, options), options) + get_anchor(dealias_and_disambiguate_times(time_tokens, options), options.merge(:context => :future)) else outer_span end end @@ -523,10 +542,10 @@ def get_repeaters(tokens) tokens.map { |token| token.get_tag(Repeater) }.compact.sort.reverse end def month_overflow?(year, month, day) - if Date.leap?(year) + if ::Date.leap?(year) day > RepeaterMonth::MONTH_DAYS_LEAP[month - 1] else day > RepeaterMonth::MONTH_DAYS[month - 1] end rescue ArgumentError