Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/comscore_ruby/core_ext/date.rb

Instance Method Summary collapse

Instance Method Details

#to_comscore_time_periodObject



2
3
4
5
6
7
8
9
10
# File 'lib/comscore_ruby/core_ext/date.rb', line 2

def to_comscore_time_period
  initial_d = Date.new(2000, 1, 1)
  if self.to_time.to_i < initial_d.to_time.to_i
    raise "#{self.strftime("%Y-%m")} is before #{self.strftime("%Y-%m")}"
  end
  year_difference = self.year - initial_d.year
  month_difference = (self.month - initial_d.month).modulo(12)
  return (year_difference * 12) + month_difference + 1
end