Class: TimeHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudability/time_helper.rb

Overview

Cloudability requires time periods formatted in YYYY-MM-01 The date must always be 1. This provides a set of helpers to always return the correct period format.

Instance Method Summary collapse

Instance Method Details

#current_monthObject

Returns the current month



21
22
23
# File 'lib/cloudability/time_helper.rb', line 21

def current_month
  DateTime.now.strftime("%Y-%m-01")
end

#last_three_monthsObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/cloudability/time_helper.rb', line 9

def last_three_months
  dt = DateTime.now

  current_month = dt.strftime("%Y-%m-01")
  last_month    = (dt << 1).strftime("%Y-%m-01")
  three_month   = (dt << 2).strftime("%Y-%m-01")
 
  hash = { current: current_month, last: last_month, three: three_month }    
  Hashie::Mash.new(hash)
end