Files
grecia/lib/age.rb
Bertocq 9e74249b02 Always use Time.current (aliases internally to Time.zone.now)
Some specs where breaking close to midnight because 30.years.ago uses zone.now and Time.now.utc.to_date doesn't.
Also this will make all codebase consistent in the way time is deal with
2017-05-24 07:54:57 +02:00

8 lines
325 B
Ruby

module Age
def self.in_years(dob, now = Time.current.to_date)
return nil unless dob.present?
# reference: http://stackoverflow.com/questions/819263/get-persons-age-in-ruby#comment21200772_819263
now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1)
end
end