Class: CloudwatchChrono::NextTime

Inherits:
Chrono::NextTime
  • Object
show all
Defined in:
lib/cloudwatch_chrono/next_time.rb

Instance Method Summary collapse

Instance Method Details

#to_timeObject

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cloudwatch_chrono/next_time.rb', line 5

def to_time
  # the longest cycle is 4 years (leap year)
  # Note that the combination of day-month and wday is OR
  max_time = time + (365 * 3 + 366).days
  while @time < max_time
    case
    when !scheduled_in_this_year?
      carry_year
    when !scheduled_in_this_month?
      carry_month
    when !scheduled_in_this_day?
      carry_day
    when !scheduled_in_this_hour?
      carry_hour
    when !scheduled_in_this_minute?
      carry_minute
    else
      return @time
    end
  end
  raise ArgumentError, "invalid cron string '#{@source}'"
end