26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/quartz/cronify.rb', line 26
def self.cronify(time,at=0)
timing = %w(0 * * * * ?)
case time
when 0.seconds...1.minute
timing[0] = "0/#{time.to_s}"
when 1.minute...1.hour
minute_frequency = time / 60
timing[1] = comma_separated_timing(minute_frequency, 59, at || 0)
when 1.hour...1.day
hour_frequency = (time / 60 / 60).round
timing[1] = at.is_a?(Time) ? at.min : at
timing[2] = comma_separated_timing(hour_frequency, 23)
when 1.day...1.month
day_frequency = (time / 24 / 60 / 60).round
timing[1] = at.is_a?(Time) ? at.min : 0
timing[2] = at.is_a?(Time) ? at.hour : at
timing[3] = comma_separated_timing(day_frequency, 31, 1)
when 1.month..12.months
month_frequency = (time / 30 / 24 / 60 / 60).round
timing[1] = at.is_a?(Time) ? at.min : 0
timing[2] = at.is_a?(Time) ? at.hour : 0
timing[3] = at.is_a?(Time) ? at.day : (at.zero? ? 1 : at)
timing[4] = comma_separated_timing(month_frequency, 12, 1)
else
return 'bummer'
end
timing.join(' ')
end
|