diff options
author | Alexandru Croitor <acroitor@gitlab.com> | 2019-09-05 16:40:16 +0300 |
---|---|---|
committer | Alexandru Croitor <acroitor@gitlab.com> | 2019-09-05 20:57:35 +0300 |
commit | 16f232d2d3a2390402fc7de721086b24a7947b33 (patch) | |
tree | 01b047e373366ea7b743de3c0f6190324edf2463 | |
parent | 1c6aa98c37f3cb4221819044294020923c14f57d (diff) | |
download | gitlab-ce-62591-fix-milestone-due-date-today-wording-rework.tar.gz |
Show remaining hours when milestone due date is today62591-fix-milestone-due-date-today-wording-rework
https://gitlab.com/gitlab-org/gitlab-ce/issues/62591#note_211861231
-rw-r--r-- | app/serializers/entity_date_helper.rb | 15 | ||||
-rw-r--r-- | spec/serializers/entity_date_helper_spec.rb | 12 |
2 files changed, 20 insertions, 7 deletions
diff --git a/app/serializers/entity_date_helper.rb b/app/serializers/entity_date_helper.rb index d8f267d7183..818199eb123 100644 --- a/app/serializers/entity_date_helper.rb +++ b/app/serializers/entity_date_helper.rb @@ -48,7 +48,10 @@ module EntityDateHelper if due_date&.past? content_tag(:strong, _('Past due')) elsif due_date&.today? - content_tag(:strong, _('Today')) + duration = distance_of_time_in_words(Time.now, due_date.end_of_day) + content = extract_duration(duration) + + "#{content} #{_('remaining')}".html_safe elsif start_date&.future? content_tag(:strong, _('Upcoming')) elsif due_date @@ -59,9 +62,7 @@ module EntityDateHelper # # Need to improve the i18n here and do a full translation # of the string instead of piecewise translations. - content = time_ago - .gsub(/\d+/) { |match| "<strong>#{match}</strong>" } - .remove('about ') + content = extract_duration(time_ago) remaining_or_ago = is_upcoming ? _('remaining') : _('ago') "#{content} #{remaining_or_ago}".html_safe @@ -70,4 +71,10 @@ module EntityDateHelper "#{content_tag(:strong, days)} #{'day'.pluralize(days)} elapsed".html_safe end end + + private + + def extract_duration(duration) + duration.gsub(/\d+/) {|match| "<strong>#{match}</strong>"}.remove('about ') + end end diff --git a/spec/serializers/entity_date_helper_spec.rb b/spec/serializers/entity_date_helper_spec.rb index 73506954965..c28184e293a 100644 --- a/spec/serializers/entity_date_helper_spec.rb +++ b/spec/serializers/entity_date_helper_spec.rb @@ -57,11 +57,17 @@ describe EntityDateHelper do end end - context 'when milestone due date is today' do + context 'when milestone due date is today and current time is 00:00:00' do let(:milestone_remaining) { date_helper_class.remaining_days_in_words(Date.today) } - it 'returns today' do - expect(milestone_remaining).to eq("<strong>Today</strong>") + it 'returns 1 day remaining' do + expect(milestone_remaining).to eq("<strong>1</strong> day remaining") + end + + it 'returns hours remaining when queried mid-day' do + Timecop.freeze(Time.utc(2017, 3, 17, 13, 10)) do + expect(milestone_remaining).to eq("<strong>11</strong> hours remaining") + end end end |