Module: Concerns::Models::PersonAge
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/kirgudu_common/concerns/models/person_age.rb
Instance Method Summary collapse
Instance Method Details
#age ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/kirgudu_common/concerns/models/person_age.rb', line 10 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 |
#days_to_next_birth_date ⇒ Object
40 41 42 43 |
# File 'app/models/kirgudu_common/concerns/models/person_age.rb', line 40 def days_to_next_birth_date nbd = self.next_birth_date nbd.nil? ? -1 : nbd - DateTime.now.utc.to_date end |
#next_birth_date ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/kirgudu_common/concerns/models/person_age.rb', line 24 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 |