Class: Daru::Offsets::YearEnd

Inherits:
DateOffsetType show all
Defined in:
lib/daru/date_time/offsets.rb

Overview

Create a year end offset

Examples:

Create a YearEnd offset

offset = Daru::Offsets::YearEnd.new
offset + DateTime.new(2012,5,5)
#=> #<DateTime: 2012-12-31T00:00:00+00:00 ((2456293j,0s,0n),+0s,2299161j)>

Constant Summary collapse

FREQ =
'YE'.freeze

Instance Method Summary collapse

Methods inherited from DateOffsetType

#freq_string, #initialize

Methods inherited from DateOffset

#-@, #initialize

Constructor Details

This class inherits a constructor from Daru::Offsets::DateOffsetType

Instance Method Details

#+(date_time) ⇒ Object



360
361
362
363
364
365
366
367
368
# File 'lib/daru/date_time/offsets.rb', line 360

def + date_time
  if on_offset?(date_time)
    DateTime.new(date_time.year + @n, 12, 31,
      date_time.hour, date_time.min, date_time.sec)
  else
    DateTime.new(date_time.year + (@n-1), 12, 31,
      date_time.hour, date_time.min, date_time.sec)
  end
end

#-(date_time) ⇒ Object



370
371
372
# File 'lib/daru/date_time/offsets.rb', line 370

def - date_time
  DateTime.new(date_time.year - 1, 12, 31)
end

#on_offset?(date_time) ⇒ Boolean

Returns:

  • (Boolean)


374
375
376
# File 'lib/daru/date_time/offsets.rb', line 374

def on_offset? date_time
  date_time.month == 12 && date_time.day == 31
end