Class: PerfectSched::CronCalc

Inherits:
Object
  • Object
show all
Defined in:
lib/perfectsched/croncalc.rb

Instance Method Summary collapse

Constructor Details

#initializeCronCalc

Returns a new instance of CronCalc.



6
7
8
9
10
# File 'lib/perfectsched/croncalc.rb', line 6

def initialize
  require 'cron-spec'
  require 'tzinfo'
  # TODO optimize
end

Instance Method Details

#next_time(cron, time, timezone) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/perfectsched/croncalc.rb', line 12

def next_time(cron, time, timezone)
  tab = CronSpec::CronSpecification.new(cron)
  tz = TZInfo::Timezone.get(timezone) if timezone
  while true
    time += 60
    t = Time.at(time)
    t = tz.utc_to_local(t.utc) if tz
    if tab.is_specification_in_effect?(t)
      return time
    end
    # FIXME break
  end
end