From fbe77781ffc9294d555c2a5b34ff04ed31b84622 Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Fri, 4 Mar 2016 14:12:40 +0100 Subject: [PATCH 1/2] 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.) --- app/helpers/people_helper.rb | 6 +++--- app/models/profile.rb | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index 78b58f8fd..a7df8d8f9 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 From 4617629098d7fe9a8c0c14ad2c88e943baa321bd Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Sat, 5 Mar 2016 10:19:40 +0100 Subject: [PATCH 2/2] Add spec for PeopleHelper#birthday_format closes #6738 --- Changelog.md | 1 + spec/helpers/people_helper_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/Changelog.md b/Changelog.md index 7a73c4745..6657dd551 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ * 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/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("")