Method: Calculations#offset_period_dates

Defined in:
lib/period_dates/core_ext.rb

#offset_period_dates(offset = 0, period = 'monthly') ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/period_dates/core_ext.rb', line 86

def offset_period_dates(offset=0,period='monthly')
    bound_dates = self.current_period_dates(period)

    if !available_periods.include?(period)
      raise PeriodDatesIncorrectPeriod, "Period must be one of this: #{available_periods.join(', ')}."
    else
      offset.abs.times do |time|
        if offset > 0
          bound_dates = bound_dates[0].next_period_dates(period)
        elsif offset < 0
          bound_dates = bound_dates[0].prev_period_dates(period)
        end
      end

      bound_dates
    end
end