Class: Daru::Offsets::YearBegin

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

Overview

Create a year begin offset

Examples:

Create a YearBegin offset

offset = Daru::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

#[email protected], #initialize

Constructor Details

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

Instance Method Details

#+(date_time) ⇒ Object


331
332
333
334
# File 'lib/daru/date_time/offsets.rb', line 331

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

#-(date_time) ⇒ Object


336
337
338
339
340
341
342
343
# File 'lib/daru/date_time/offsets.rb', line 336

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

#on_offset?(date_time) ⇒ Boolean

Returns:

  • (Boolean)

345
346
347
# File 'lib/daru/date_time/offsets.rb', line 345

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