Class: DaruLite::Offsets::YearEnd

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

Overview

Create a year end offset

Examples:

Create a YearEnd offset

offset = DaruLite::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 DaruLite::Offsets::DateOffsetType

Instance Method Details

#+(other) ⇒ Object



369
370
371
372
373
374
375
376
377
# File 'lib/daru_lite/date_time/offsets.rb', line 369

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

#-(other) ⇒ Object



379
380
381
# File 'lib/daru_lite/date_time/offsets.rb', line 379

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

#on_offset?(date_time) ⇒ Boolean

Returns:

  • (Boolean)


383
384
385
# File 'lib/daru_lite/date_time/offsets.rb', line 383

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