Period#next should return today time if it is first run and not too late

This commit is contained in:
Dzmitry Plashchynski
2015-03-07 04:13:59 +02:00
parent 368cdde296
commit 6d90cb3233
4 changed files with 26 additions and 11 deletions

View File

@@ -56,7 +56,7 @@ module Crono
logger.info "Jobs:"
Crono.scheduler.jobs.each do |job|
logger.info job.description
logger.info %{"#{job.performer}" with rule "#{job.period.description}" next time will perform at #{job.next}}
end
end

View File

@@ -6,8 +6,13 @@ module Crono
end
def next(since: nil)
since ||= Time.now
@period.since(since).change({hour: @at_hour, min: @at_min}.compact)
if since.nil?
@next = Time.now.change(time_atts)
return @next if @next.future?
since = Time.now
end
@period.since(since).change(time_atts)
end
def description
@@ -27,5 +32,10 @@ module Crono
raise "Unknown 'at' format"
end
end
private
def time_atts
{hour: @at_hour, min: @at_min}.compact
end
end
end