Class: Daru::Offsets::MonthBegin
Overview
Create a month begin offset
Constant Summary
collapse
- FREQ =
'MB'.freeze
Instance Method Summary
collapse
#freq_string, #initialize
Methods inherited from DateOffset
#-@, #initialize
Instance Method Details
#+(date_time) ⇒ Object
260
261
262
263
264
265
266
267
268
|
# File 'lib/daru/date_time/offsets.rb', line 260
def + date_time
@n.times do
days_in_month = Daru::MONTH_DAYS[date_time.month]
days_in_month += 1 if date_time.leap? && date_time.month == 2
date_time += (days_in_month - date_time.day + 1)
end
date_time
end
|
#-(date_time) ⇒ Object
270
271
272
273
274
275
276
277
278
|
# File 'lib/daru/date_time/offsets.rb', line 270
def - date_time
@n.times do
date_time = date_time << 1 if on_offset?(date_time)
date_time = DateTime.new(date_time.year, date_time.month, 1,
date_time.hour, date_time.min, date_time.sec)
end
date_time
end
|
#on_offset?(date_time) ⇒ Boolean
280
281
282
|
# File 'lib/daru/date_time/offsets.rb', line 280
def on_offset? date_time
date_time.day == 1
end
|