Age calculator and formatter (with leap-year support..duh)
Add this line to your application's Gemfile:
gem 'stinky_cheese'
And then execute:
$ bundle
Or install it yourself as:
$ gem install stinky_cheese
Calculate the age given a date of birth:
dob = Date.parse('1993-12-09')
StinkyCheese.age_from_dob(dob)
StinkyCheese.age_from_dob can handle inputs that are either String, Date, DateTime, and Time Objects as well!
dob = '1993-12-09'
StinkyCheese.age_from_dob(dob)
The date of death parameter can also be set to calculate the age a person died at:
dob = '1931-01-09'
dod = '1971-12-10'
StinkyCheese.age_from_dob(dob, dod)
This will yield 40
StinkyCheese also gives a vague age teaser given an age. For example:
StinkyCheese.stage_of_life(42)
This will yields "Early 40's"
StinkyCheese.stage_of_life(2)
Will yield "Child"
Bug reports and pull requests are welcome on GitHub at https://github.com/Spokeo/stinky_cheese.
The gem is available as open source under the terms of the MIT License.