lib/fugit/cron.rb in fugit-0.9.6 vs lib/fugit/cron.rb in fugit-1.0.0

- old
+ new

@@ -56,35 +56,33 @@ def self.do_parse(s) parse(s) || fail(ArgumentError.new("not a cron string #{s.inspect}")) end - class TimeCursor # TODO at some point, use ZoTime + class TimeCursor def initialize(t) - @t = t.is_a?(TimeCursor) ? t.time : t + @t = t.is_a?(TimeCursor) ? t.time : ::EtOrbi.make_time(t) end def time; @t; end def to_i; @t.to_i; end - %w[ year month day wday hour min sec ] + %w[ year month day wday hour min sec wday_in_month ] .collect(&:to_sym).each { |k| define_method(k) { @t.send(k) } } def inc(i) - u = @t.utc? - @t = ::Time.at(@t.to_i + i) - @t = @t.utc if u + @t = @t + i self end def dec(i); inc(-i); end def inc_month y = @t.year m = @t.month + 1 if m == 13; m = 1; y += 1; end - @t = Time.send((@t.utc? ? :utc : :local), y, m) + @t = ::EtOrbi.make(y, m) self end def inc_day; inc((24 - @t.hour) * 3600 - @t.min * 60 - @t.sec); end def inc_hour; inc((60 - @t.min) * 60 - @t.sec); end def inc_min; inc(60 - @t.sec); end @@ -106,24 +104,10 @@ def dec_sec(seconds) target = seconds.reverse.find { |s| s < @t.sec } || seconds.last inc(target - @t.sec) end - - def count_weeks(inc) - c = 0 - t = @t - until t.month != @t.month - c += 1 - t += inc * (7 * 24 * 3600) - end - c - end - - def wday_in_month - [ count_weeks(-1), - count_weeks(1) ] - end end def month_match?(nt); ( ! @months) || @months.include?(nt.month); end def hour_match?(nt); ( ! @hours) || @hours.include?(nt.hour); end def min_match?(nt); ( ! @minutes) || @minutes.include?(nt.min); end @@ -170,17 +154,16 @@ end def match?(t) t = Fugit.do_parse_at(t) - t = TimeCursor.new(t) month_match?(t) && day_match?(t) && hour_match?(t) && min_match?(t) && sec_match?(t) end - def next_time(from=Time.now) + def next_time(from=::EtOrbi::EoTime.now) t = TimeCursor.new(from) loop do #p [ :l, Fugit.time_to_s(t.time) ] @@ -194,11 +177,11 @@ end t.time end - def previous_time(from=Time.now) + def previous_time(from=::EtOrbi::EoTime.now) t = TimeCursor.new(from) loop do #p [ :l, Fugit.time_to_s(t.time) ] @@ -226,10 +209,10 @@ FREQUENCY_CACHE["#{to_cron_s}|#{year}"] ||= begin deltas = [] - t = Time.parse("#{year}-01-01") - 1 + t = EtOrbi.make_time("#{year}-01-01") - 1 t0 = nil t1 = nil loop do t1 = next_time(t) deltas << (t1 - t).to_i if t0