Class: MudratProjector::DateDiff::MonthCalculator
Instance Attribute Summary
#first_unit
Attributes inherited from Calculator
#from, #to
Class Method Summary
collapse
Instance Method Summary
collapse
#calculate, #initialize
Methods inherited from Calculator
#calculate
Class Method Details
.advance(intervals, from: from) ⇒ Object
158
159
160
161
162
163
164
165
166
|
# File 'lib/mudrat_projector/date_diff.rb', line 158
def self.advance intervals, from: from
if intervals < 1
days_in_month = Date.new(from.year, from.month, -1).day
days = intervals * days_in_month
DayCalculator.advance days, from: from
else
intervals.times.inject from do |date, _| date.next_month; end
end
end
|
Instance Method Details
#advance_one_unit(date) ⇒ Object
150
151
152
|
# File 'lib/mudrat_projector/date_diff.rb', line 150
def advance_one_unit date
date.next_month
end
|
#fetch_unit(date) ⇒ Object
145
146
147
148
|
# File 'lib/mudrat_projector/date_diff.rb', line 145
def fetch_unit date
start_of_month = Date.new(date.year, date.month)
(start_of_month..(start_of_month.next_month - 1))
end
|
#rewind_one_unit(date) ⇒ Object
154
155
156
|
# File 'lib/mudrat_projector/date_diff.rb', line 154
def rewind_one_unit date
date.prev_month
end
|