class Rufus::CronLine
def next_time (now = Time.now)
This is raw, 3 secs to iterate over 1 year on my macbook :( brutal.
Returns the next time that this cron line is supposed to 'fire'
def next_time (now = Time.now) # # position now to the next cron second if @seconds next_sec = @seconds.find { |s| s > now.sec } || 60 + @seconds.first now += next_sec - now.sec else now += 1 end # # prepare sec jump array sjarray = nil if @seconds sjarray = [] i = @seconds.index(now.sec) ii = i loop do cur = @seconds[ii] ii += 1 ii = 0 if ii == @seconds.size nxt = @seconds[ii] nxt += 60 if ii == 0 sjarray << (nxt - cur) break if ii == i end else sjarray = [ 1 ] end # # ok, seek... i = 0 loop do return now if matches?(now) now += sjarray[i] i += 1 i = 0 if i == sjarray.size # danger... potentially no exit... end nil end