class Periodic
Definitions
def initialize(seconds, minutes, hours, weekday, monthday, month, flags = Flags.new)
Create a new schedule with the given parameters.
Implementation
def initialize(seconds, minutes, hours, weekday, monthday, month, flags = Flags.new)
super(flags)
@seconds = seconds
@minutes = minutes
@hours = hours
@weekday = weekday
@monthday = monthday
@month = month
end
def increment(time = nil)
Compute the next execution time after the given time.
Implementation
def increment(time = nil)
time = Time.from(time) || Time.now
units = [@seconds, @minutes, @hours, @weekday, @monthday, @month]
index = 1
# Step the smallest unit first:
units[0].increment(time)
# Now try to fit the rest of the schedule:
while index < units.length
unit = units[index]
# puts "Checking #{unit} at #{index}... -> #{time}"
# If the unit is not already at the desired time, increment it:
unless unit.include?(time)
# puts "Incrementing #{unit} at #{index}..."
unit.increment(time)
# puts "-> #{time}"
# Reset all smaller units:
units[0...index].each do |unit|
# puts "Resetting #{unit}..."
unit.reset(time)
end
end
index += 1
end
return time.normalize!
end