diff --git a/Changelog.md b/Changelog.md index 4a7c05ebd..b09069f2e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -146,6 +146,7 @@ Contributions are very welcome, the hard work is done! * Fix internal server error when trying to log out of an expired session [#6707](https://github.com/diaspora/diaspora/pull/6707) * Only mark unread notifications as read [#6711](https://github.com/diaspora/diaspora/pull/6711) * Use https for OEmbeds [#6748](https://github.com/diaspora/diaspora/pull/6748) +* Fix birthday issues on leap days [#6738](https://github.com/diaspora/diaspora/pull/6738) ## Features * Added the footer to conversation pages [#6710](https://github.com/diaspora/diaspora/pull/6710) diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index 35c26f936..8d5e14c11 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -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 diff --git a/app/models/profile.rb b/app/models/profile.rb index b89959232..5626f058b 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -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 diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rb index 2c5f13927..24f0bf445 100644 --- a/spec/helpers/people_helper_spec.rb +++ b/spec/helpers/people_helper_spec.rb @@ -10,6 +10,18 @@ describe PeopleHelper, :type => :helper do @person = FactoryGirl.create(:person) end + describe "#birthday_format" do + it "contains the birth year if available" do + birthday = Date.new 2016, 3, 5 + expect(birthday_format(birthday)).to include "2016" + end + + it "does not contain the birth year if placeholder year is used" do + birthday = Date.new 1004, 3, 5 + expect(birthday_format(birthday)).not_to include "1004" + end + end + describe "#person_image_link" do it "returns an empty string if person is nil" do expect(person_image_link(nil)).to eq("")