lib/timeliness/parser.rb in timeliness-0.3.6 vs lib/timeliness/parser.rb in timeliness-0.3.7

- old
+ new

@@ -65,22 +65,22 @@ when :time values[0..2] = current_date(options) when nil dummy_date = current_date(options) values[0] ||= dummy_date[0] - values[1] ||= dummy_date[1] + values[1] ||= dummy_date[1] unless values.values_at(0,2).all? values[2] ||= dummy_date[2] end end def current_date(options) now = if options[:now] options[:now] elsif options[:zone] current_time_in_zone(options[:zone]) else - Timeliness.date_for_time_type + evaluate_date_for_time_type end now.is_a?(Array) ? now[0..2] : [now.year, now.month, now.day] end def current_time_in_zone(zone) @@ -137,10 +137,20 @@ end # Enforce strict date part validity which the Time class does not. # Only does full date check if month and day are possibly invalid. def fast_date_valid_with_fallback(year, month, day) - month < 13 && (day < 29 || Date.valid_civil?(year, month, day)) + month && month < 13 && (day < 29 || Date.valid_civil?(year, month, day)) + end + + def evaluate_date_for_time_type + case Timeliness.date_for_time_type + when Array + Timeliness.date_for_time_type + when Proc + v = Timeliness.date_for_time_type.call + [v.year, v.month, v.day] + end end end end