Sha256: 6e0c5f51065c726989f1c4cfe2c7942161407915ef4ed30d3cad2168a363b433

Contents?: true

Size: 738 Bytes

Versions: 6

Compression:

Stored size: 738 Bytes

Contents

class Date

  # http://stackoverflow.com/questions/819263/get-persons-age-in-ruby
  #------------------------------------------------------------------------------
  def to_age
    now = Time.now.utc.to_date
    now.year - self.year - ((now.month > self.month || (now.month == self.month && now.day >= self.day)) ? 0 : 1)
  end
  
  #------------------------------------------------------------------------------
  def localize(options = {})
    options = {:format => options} if options.class == String      
    I18n.localize(self, options)
  end

  # Create a unique sortable index for this date
  #------------------------------------------------------------------------------
  def to_index
    yday + (year-2000) * 1000
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dm_ruby_extensions-1.0.9 lib/dm_ruby_extensions/extend_date.rb
dm_ruby_extensions-1.0.8 lib/dm_ruby_extensions/extend_date.rb
dm_ruby_extensions-1.0.7 lib/dm_ruby_extensions/extend_date.rb
dm_ruby_extensions-1.0.6 lib/dm_ruby_extensions/extend_date.rb
dm_ruby_extensions-1.0.5 lib/dm_ruby_extensions/extend_date.rb
dm_ruby_extensions-1.0.0 lib/dm_ruby_extensions/extend_date.rb