Method: IceCube::WeeklyRule#wday_offset
- Defined in:
- lib/ice_cube/rules/weekly_rule.rb
#wday_offset(step_time, start_time) ⇒ Object
Calculate how many days to the first wday validation in the correct interval week. This may move backwards within the week if starting in an interval week with earlier validations.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ice_cube/rules/weekly_rule.rb', line 45 def wday_offset(step_time, start_time) return 0 if step_time == start_time wday_validations = other_interval_validations.select { |v| v.type == :wday } return 0 if wday_validations.none? days = step_time.to_date - start_time.to_date interval = base_interval_validation.validate(step_time, start_time).to_i min_wday = wday_validations.map { |v| TimeUtil.normalize_wday(v.day, week_start) }.min step_wday = TimeUtil.normalize_wday(step_time.wday, week_start) days + interval - step_wday + min_wday end |