lib/rufus/scheduler/util.rb in rufus-scheduler-3.2.2 vs lib/rufus/scheduler/util.rb in rufus-scheduler-3.3.0

- old
+ new

@@ -36,48 +36,47 @@ opts[:no_error] = true parse_cron(o, opts) || parse_in(o, opts) || # covers 'every' schedule strings parse_at(o, opts) || - fail(ArgumentError.new("couldn't parse \"#{o}\"")) + fail(ArgumentError.new("couldn't parse #{o.inspect} (#{o.class})")) end - def self.parse_in(o, opts={}) + def self.parse_cron(o, opts) - o.is_a?(String) ? parse_duration(o, opts) : o - end + CronLine.new(o) - def self.parse_at(o, opts={}) + rescue ArgumentError => ae - Rufus::Scheduler::ZoTime.parse(o, opts).time - - rescue StandardError => se - return nil if opts[:no_error] - fail se + fail ae end - def self.parse_cron(o, opts) + def self.parse_in(o, opts={}) - CronLine.new(o) + #o.is_a?(String) ? parse_duration(o, opts) : o + return parse_duration(o, opts) if o.is_a?(String) + return o if o.is_a?(Numeric) + + fail ArgumentError.new("couldn't parse time point in #{o.inspect}") + rescue ArgumentError => ae return nil if opts[:no_error] fail ae end - def self.parse_to_time(o) + def self.parse_at(o, opts={}) - t = o - t = parse(t) if t.is_a?(String) - t = Time.now + t if t.is_a?(Numeric) + return o if o.is_a?(Rufus::Scheduler::ZoTime) + return Rufus::Scheduler::ZoTime.make(o) if o.is_a?(Time) + Rufus::Scheduler::ZoTime.parse(o, opts) - fail ArgumentError.new( - "cannot turn #{o.inspect} to a point in time, doesn't make sense" - ) unless t.is_a?(Time) + rescue StandardError => se - t + return nil if opts[:no_error] + fail se end DURATIONS2M = [ [ 'y', 365 * 24 * 3600 ], [ 'M', 30 * 24 * 3600 ],