Class: Moment::CronTrigger
Constant Summary collapse
- LeapYearMonthDays =
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- CommonYearMonthDays =
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
Instance Attribute Summary collapse
-
#cron_expr ⇒ Object
Returns the value of attribute cron_expr.
-
#day ⇒ Object
Returns the value of attribute day.
-
#hour ⇒ Object
Returns the value of attribute hour.
-
#min ⇒ Object
Returns the value of attribute min.
-
#month ⇒ Object
Returns the value of attribute month.
-
#sec ⇒ Object
Returns the value of attribute sec.
-
#wday ⇒ Object
Returns the value of attribute wday.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #fire_time_after(time) ⇒ Object
-
#initialize(expr) ⇒ CronTrigger
constructor
A new instance of CronTrigger.
Constructor Details
#initialize(expr) ⇒ CronTrigger
Returns a new instance of CronTrigger.
8 9 10 11 |
# File 'lib/cron_trigger.rb', line 8 def initialize(expr) super() self.cron_expr = expr end |
Instance Attribute Details
#cron_expr ⇒ Object
Returns the value of attribute cron_expr.
6 7 8 |
# File 'lib/cron_trigger.rb', line 6 def cron_expr @cron_expr end |
#day ⇒ Object
Returns the value of attribute day.
6 7 8 |
# File 'lib/cron_trigger.rb', line 6 def day @day end |
#hour ⇒ Object
Returns the value of attribute hour.
6 7 8 |
# File 'lib/cron_trigger.rb', line 6 def hour @hour end |
#min ⇒ Object
Returns the value of attribute min.
6 7 8 |
# File 'lib/cron_trigger.rb', line 6 def min @min end |
#month ⇒ Object
Returns the value of attribute month.
6 7 8 |
# File 'lib/cron_trigger.rb', line 6 def month @month end |
#sec ⇒ Object
Returns the value of attribute sec.
6 7 8 |
# File 'lib/cron_trigger.rb', line 6 def sec @sec end |
#wday ⇒ Object
Returns the value of attribute wday.
6 7 8 |
# File 'lib/cron_trigger.rb', line 6 def wday @wday end |
#year ⇒ Object
Returns the value of attribute year.
6 7 8 |
# File 'lib/cron_trigger.rb', line 6 def year @year end |
Instance Method Details
#fire_time_after(time) ⇒ Object
19 20 21 22 23 24 25 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cron_trigger.rb', line 19 def fire_time_after(time) sec, min, hour, day, month, year, wday, yday, isdst, zone = time.to_a loop do # year unless @year.nil? or @year.include?(year) return nil if year > @year.max year = @year.detect do |y| y > year end # next allowable year end # month unless @month.include?(month) # next allowable month next_month = @month.detect(lambda { @month.min }) do |m| m > month end # reset everything lower day, hour, min, sec = @day.min, @hour.min, @min.min, @sec.min # carry case if next_month < month month = next_month year += 1 retry end month = next_month end # day month_days = (1 .. month_days(year, month)) days = @day.select do |d| month_days === d end unless days.include?(day) next_day = days.detect(lambda { days.min }) do |d| d > day end hour, min, sec = @hour.min, @min.min, @sec.min if next_day.nil? or next_day < day day = next_day.nil? ? @day.min : next_day month += 1 retry end day = next_day end # hour unless @hour.include?(hour) next_hour = @hour.detect(lambda { @hour.min }) do |h| h > hour end min, sec = @min.min, @sec.min if next_hour < hour hour = next_hour day += 1 retry end hour = next_hour end # min unless @min.include?(min) next_min = @min.detect(lambda { @min.min }) do |m| m > min end sec = @sec.min if next_min < min min = next_min hour += 1 retry end min = next_min end # sec unless @sec.include?(sec) next_sec = @sec.detect(lambda { @sec.min }) do |s| s > sec end if next_sec < sec sec = next_sec min += 1 retry end sec = next_sec end break end Time.local sec, min, hour, day, month, year, wday, yday, isdst, zone end |