module PeopleHelper # Show someone's birthday in human-readable form, # plus their current age. # # Example output: "10th October 1975 (age 31)" def show_birthday(bday) if bday.blank? out = nil else current_date = DateTime.now age = current_date.year - bday.year # If someone hasn't had their birthday yet this year, # we need to recalculate their age. closest_bday = Date.new(current_date.year, bday.month, bday.day) if closest_bday > current_date age -= 1 end out = human_date(bday) + ' (age ' + age.to_s + ')' end out end end