Use 1004 as our placeholder birth year because 1004 was a leap year. (Well, actually, people in 1004 probably had no idea what a leap year is. Or red tests. Or code.)

This commit is contained in:
Dennis Schubert 2016-03-04 14:12:40 +01:00 committed by Steffen van Bergerem
parent 69f08a4a7e
commit fbe77781ff
2 changed files with 9 additions and 9 deletions

View file

@ -16,10 +16,10 @@ module PeopleHelper
end
def birthday_format(bday)
if bday.year == 1000
I18n.l bday, :format => I18n.t('date.formats.birthday')
if bday.year <= 1004
I18n.l bday, format: I18n.t("date.formats.birthday")
else
I18n.l bday, :format => I18n.t('date.formats.birthday_with_year')
I18n.l bday, format: I18n.t("date.formats.birthday_with_year")
end
end

View file

@ -113,20 +113,20 @@ class Profile < ActiveRecord::Base
end
def date= params
if ['month', 'day'].all? { |key| params[key].present? }
params['year'] = '1000' if params['year'].blank?
if Date.valid_civil?(params['year'].to_i, params['month'].to_i, params['day'].to_i)
self.birthday = Date.new(params['year'].to_i, params['month'].to_i, params['day'].to_i)
if %w(month day).all? {|key| params[key].present? }
params["year"] = "1004" if params["year"].blank?
if Date.valid_civil?(params["year"].to_i, params["month"].to_i, params["day"].to_i)
self.birthday = Date.new(params["year"].to_i, params["month"].to_i, params["day"].to_i)
else
@invalid_birthday_date = true
end
elsif [ 'year', 'month', 'day'].all? { |key| params[key].blank? }
elsif %w(year month day).all? {|key| params[key].blank? }
self.birthday = nil
end
end
def formatted_birthday
birthday.to_s(:long).gsub(', 1000', '') if birthday.present?
birthday.to_s(:long).gsub(/, 100[0|4]/, "") if birthday.present?
end
def bio_message