Class: DaruLite::Offsets::YearBegin

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

Overview

Create a year begin offset

Examples:

Create a YearBegin offset

offset = DaruLite::Offsets::YearBegin.new(3)
offset + DateTime.new(2012,5,5)
#=> #<DateTime: 2015-01-01T00:00:00+00:00 ((2457024j,0s,0n),+0s,2299161j)>

Constant Summary collapse

FREQ =
'YB'.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



340
341
342
343
# File 'lib/daru_lite/date_time/offsets.rb', line 340

def +(other)
  DateTime.new(other.year + @n, 1, 1,
               other.hour, other.min, other.sec)
end

#-(other) ⇒ Object



345
346
347
348
349
350
351
352
# File 'lib/daru_lite/date_time/offsets.rb', line 345

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

#on_offset?(date_time) ⇒ Boolean

Returns:

  • (Boolean)


354
355
356
# File 'lib/daru_lite/date_time/offsets.rb', line 354

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