refactors age calculation
This commit is contained in:
@@ -42,11 +42,12 @@ class Poll
|
||||
|
||||
private
|
||||
|
||||
def voter_age(date_of_birth)
|
||||
if date_of_birth.blank?
|
||||
def voter_age(dob)
|
||||
if dob.blank?
|
||||
nil
|
||||
else
|
||||
((Date.today - date_of_birth.to_date).to_i / 365.25).to_i
|
||||
now = Time.now.utc.to_date
|
||||
now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -250,7 +250,10 @@ class User < ActiveRecord::Base
|
||||
if date_of_birth.blank?
|
||||
nil
|
||||
else
|
||||
((Date.today - date_of_birth.to_date).to_i / 365.25).to_i
|
||||
now = Time.now.utc.to_date
|
||||
now.year - date_of_birth.year - (
|
||||
(now.month > date_of_birth.month || (now.month == date_of_birth.month && now.day >= date_of_birth.day)
|
||||
) ? 0 : 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user