Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/dm_ruby_extensions/extend_date.rb

Instance Method Summary collapse

Instance Method Details

#localize(options = {}) ⇒ Object




12
13
14
15
# File 'lib/dm_ruby_extensions/extend_date.rb', line 12

def localize(options = {})
  options = { format: options } if options.instance_of?(String)
  I18n.localize(self, **options)
end

#to_ageObject



6
7
8
9
# File 'lib/dm_ruby_extensions/extend_date.rb', line 6

def to_age
  now = Time.now.utc.to_date
  now.year - year - (now.month > month || (now.month == month && now.day >= day) ? 0 : 1)
end

#to_indexObject

Create a unique sortable index for this date




19
20
21
# File 'lib/dm_ruby_extensions/extend_date.rb', line 19

def to_index
  yday + (year - 2000) * 1000
end