lib/timespan.rb in timespan-0.5.6.1 vs lib/timespan.rb in timespan-0.5.7

- old
+ new

@@ -1,9 +1,10 @@ require 'duration' require 'chronic' require 'chronic_duration' require 'spanner' +require 'time-lord' # Range intersection that works with dates! require 'sugar-high/range' require 'sugar-high/delegate' require 'sugar-high/kind_of' @@ -55,11 +56,11 @@ validate! if options == {} options = {:duration => options} if options.kind_of? Numeric case options - when Duration, String + when TimeLord::Period, ::Duration, String options = {:duration => options} end configure! options @@ -192,17 +193,25 @@ Chronic.parse(time) when Date, DateTime time.to_time when Duration (Time.now + time).to_time + when TimeLord::Period + (Time.now + time).to_time + when TimeLord::Time + (Time.now + time.moment).to_time when Time time else - raise ArgumentError, "A valid time must be either a String, Duration, Date, Time or DateTime, was: #{time.inspect} (#{time.class})" + raise ArgumentError, "A valid time must be one of #{valid_time_classes.inspect}, was: #{time.inspect} (#{time.class})" end end protected + + def valid_time_classes + [String, Duration, Date, Time, DateTime, TimeLord::Period, TimeLord::Time] + end attr_reader :init_options def first_from keys, options = {} keys.select {|key| options[key] }.first \ No newline at end of file