class Cyclical::WeeklyRule
holds daily rule configuration
Public Instance Methods
aligned?(time, base)
click to toggle source
check if time is aligned to a base time, including interval check
# File lib/cyclical/rules/weekly_rule.rb, line 8 def aligned?(time, base) return false unless ((base.beginning_of_week - time.beginning_of_week) / 604800).to_i % @interval == 0 # 604800 = 7.days return false unless [time.hour, time.min, time.sec] == [base.hour, base.min, base.sec] # the shortest filter we support is for days return false unless base.wday == time.wday || weekday_filters # wow, passed every test true end
step()
click to toggle source
default step of the rule
# File lib/cyclical/rules/weekly_rule.rb, line 19 def step @interval.weeks end
Protected Instance Methods
align(time, base)
click to toggle source
# File lib/cyclical/rules/weekly_rule.rb, line 43 def align(time, base) time = time.beginning_of_week + base.wday.days unless time.wday == base.wday || weekday_filters # compensate crossing DST barrier (oh my...) offset = time.beginning_of_day.utc_offset time = time.beginning_of_day + base.hour.hours + base.min.minutes + base.sec.seconds time += (offset - time.utc_offset) time end
potential_next(current, base)
click to toggle source
Calls superclass method
Cyclical::Rule#potential_next
# File lib/cyclical/rules/weekly_rule.rb, line 25 def potential_next(current, base) candidate = super(current, base) rem = ((base.beginning_of_week - candidate.beginning_of_week) / 604800).to_i % @interval return candidate if rem == 0 (candidate + rem.weeks).beginning_of_week end
potential_previous(current, base)
click to toggle source
Calls superclass method
Cyclical::Rule#potential_previous
# File lib/cyclical/rules/weekly_rule.rb, line 34 def potential_previous(current, base) candidate = super(current, base) rem = ((base.beginning_of_week - candidate.beginning_of_week) / 604800).to_i % @interval return candidate if rem == 0 (candidate + rem.weeks - step).end_of_week end
weekday_filters()
click to toggle source
# File lib/cyclical/rules/weekly_rule.rb, line 54 def weekday_filters filters(:weekdays) || filters(:monthdays) || filters(:yeardays) || filters(:yeardays) || filters(:weeks) || filters(:months) end