module KirguduBase module Concerns::Models::PersonAge extend ActiveSupport::Concern included do end def age today = DateTime.now.utc.to_date bd = if self.respond_to?(:birth_date) self.birth_date.to_date elsif self.respond_to?(:birthdate) self.birthdate.to_date else nil end rescue nil bd.nil? ? nil : today.year - bd.year - (bd.change(:year => today.year) > today ? 1 : 0) end def next_birth_date ag = self.age if ag bd = if self.respond_to?(birth_date) self.birth_date.to_date elsif self.respond_to?(birthdate) self.birthdate.to_date else nil end bd.nil? ? nil : bd + (ag+1).years else nil end end def days_to_next_birth_date nbd = self.next_birth_date nbd.nil? ? -1 : nbd - DateTime.now.utc.to_date end end end