Class: Daru::Offsets::MonthEnd
- Inherits:
-
DateOffset
- Object
- DateOffset
- Daru::Offsets::MonthEnd
- Defined in:
- lib/daru/date_time/offsets.rb
Overview
Create a month end offset
Instance Method Summary collapse
- #+(date_time) ⇒ Object
- #-(date_time) ⇒ Object
- #freq_string ⇒ Object
-
#initialize(n = 1) ⇒ MonthEnd
constructor
A new instance of MonthEnd.
- #on_offset?(date_time) ⇒ Boolean
Constructor Details
#initialize(n = 1) ⇒ MonthEnd
Returns a new instance of MonthEnd.
290 291 292 |
# File 'lib/daru/date_time/offsets.rb', line 290 def initialize n=1 @n = n end |
Instance Method Details
#+(date_time) ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/daru/date_time/offsets.rb', line 298 def + date_time @n.times do date_time = date_time >> 1 if on_offset?(date_time) days_in_month = Daru::MONTH_DAYS[date_time.month] days_in_month += 1 if date_time.leap? and date_time.month == 2 date_time = date_time + (days_in_month - date_time.day) end date_time end |
#-(date_time) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/daru/date_time/offsets.rb', line 310 def - date_time @n.times do date_time = date_time << 1 days_in_month = Daru::MONTH_DAYS[date_time.month] days_in_month += 1 if date_time.leap? and date_time.month == 2 date_time = date_time + (days_in_month - date_time.day) end date_time end |
#freq_string ⇒ Object
294 295 296 |
# File 'lib/daru/date_time/offsets.rb', line 294 def freq_string (@n == 1 ? '' : @n.to_s) + 'ME' end |
#on_offset?(date_time) ⇒ Boolean
322 323 324 |
# File 'lib/daru/date_time/offsets.rb', line 322 def on_offset? date_time (date_time + 1).day == 1 end |