implements Date#age_in_years extension method

This commit is contained in:
kikito
2017-02-03 12:46:07 +01:00
parent 699f3b34f7
commit 3535cfc0d6
3 changed files with 64 additions and 0 deletions

8
lib/date_ext.rb Normal file
View File

@@ -0,0 +1,8 @@
module AgeInYears
def age_in_years(now = Time.now.utc.to_date)
# reference: http://stackoverflow.com/questions/819263/get-persons-age-in-ruby#comment21200772_819263
now.year - year - ((now.month > month || (now.month == month && now.day >= day)) ? 0 : 1)
end
end
Date.include(AgeInYears)