Class Rufus::Scheduler::CronLine
In: lib/rufus/scheduler/cronline.rb
Parent: Object

A ‘cron line’ is a line in the sense of a crontab (man 5 crontab) file line.

Methods

Constants

NEXT_TIME_MAX_YEARS = 14   The max number of years in the future or the past before giving up searching for next_time or previous_time respectively
WEEKDAYS = %w[ sun mon tue wed thu fri sat ]
DAY_S = 24 * 3600
RANGE_REGEX = /\A(\*|-?\d{1,2})(?:-(-?\d{1,2}))?(?:\/(\d{1,2}))?\z/

Attributes

cache  [R] 
days  [R] 
hours  [R] 
minutes  [R] 
months  [R] 
original  [R]  The string used for creating this cronline instance.
original_timezone  [R] 
seconds  [R] 
timezone  [R] 
weekdays  [R]  attr_reader :monthdays # reader defined below

Public Class methods

Public Instance methods

Returns the shortest delta between two potential occurences of the schedule described by this cronline.

.

For a simple cronline like "*/5 * * * *", obviously the frequency is five minutes. Why does this method look at a whole year of next_time ?

Consider "* * * * sun#2,sun#3", the computed frequency is 1 week (the shortest delta is the one between the second sunday and the third sunday). This method takes no chance and runs next_time for the span of a whole year and keeps the shortest.

Of course, this method can get VERY slow if you call on it a second- based cronline…

Returns a quickly computed approximation of the frequency for this cron line.

brute_frequency, on the other hand, will compute the frequency by examining a whole year, that can take more than seconds for a seconds level cron…

Returns true if the given time matches this cron line.

Returns the next time that this cron line is supposed to ‘fire‘

This is raw, 3 secs to iterate over 1 year on my macbook :( brutal. (Well, I was wrong, takes 0.001 sec on 1.8.7 and 1.9.1)

This method accepts an optional Time parameter. It‘s the starting point for the ‘search’. By default, it‘s Time.now

Note that the time instance returned will be in the same time zone that the given start point Time (thus a result in the local time zone will be passed if no start time is specified (search start time set to Time.now))

  Rufus::Scheduler::CronLine.new('30 7 * * *').next_time(
    Time.mktime(2008, 10, 24, 7, 29))
  #=> Fri Oct 24 07:30:00 -0500 2008

  Rufus::Scheduler::CronLine.new('30 7 * * *').next_time(
    Time.utc(2008, 10, 24, 7, 29))
  #=> Fri Oct 24 07:30:00 UTC 2008

  Rufus::Scheduler::CronLine.new('30 7 * * *').next_time(
    Time.utc(2008, 10, 24, 7, 29)).localtime
  #=> Fri Oct 24 02:30:00 -0500 2008

(Thanks to K Liu for the note and the examples)

Returns the previous time the cronline matched. It‘s like next_time, but for the past.

Returns an array of 6 arrays (seconds, minutes, hours, days, months, weekdays). This method is mostly used by the cronline specs.

to_array()

Alias for to_a

Protected Instance methods

def monthday_match?(zt, values)

  return true if values.nil?

  today_values = monthdays(zt)

  (today_values & values).any?

end

FIXME: Eventually split into day_match?, hour_match? and monthdays_match?o

[Validate]