Module: Decidim::Kids::AgeMethods

Included in:
AuthorizeMinor, MinorAccountForm, ParticipatorySpaceContextOverride, UserOverride
Defined in:
lib/decidim/kids/age_methods.rb

Instance Method Summary collapse

Instance Method Details

#age_from_birthday(birthday) ⇒ Object



12
13
14
# File 'lib/decidim/kids/age_methods.rb', line 12

def age_from_birthday(birthday)
  ((Time.zone.now - birthday.to_time) / 1.year.seconds).floor
end

#age_from_date(string_date) ⇒ Object



6
7
8
9
10
# File 'lib/decidim/kids/age_methods.rb', line 6

def age_from_date(string_date)
  age_from_birthday(Date.parse(string_date))
rescue TypeError, ::Date::Error
  nil
end