diff options
author | Heinrich Lee Yu <heinrich@gitlab.com> | 2018-11-30 07:03:35 +0300 |
---|---|---|
committer | Heinrich Lee Yu <hleeyu@gmail.com> | 2018-12-20 02:28:28 +0300 |
commit | 95aae95a1cbb55facd127c74d6c044b13533f3fe (patch) | |
tree | 6ecf27a219ee09f9e9d294d8304df2cb93c4da3d /app/serializers/entity_date_helper.rb | |
parent | 48d2c02efe7697914591d7381ce1c72d68eed336 (diff) |
Code style changes and refactor
Diffstat (limited to 'app/serializers/entity_date_helper.rb')
-rw-r--r-- | app/serializers/entity_date_helper.rb | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/app/serializers/entity_date_helper.rb b/app/serializers/entity_date_helper.rb index 87bba87a0ed..f515abe5917 100644 --- a/app/serializers/entity_date_helper.rb +++ b/app/serializers/entity_date_helper.rb @@ -44,13 +44,10 @@ module EntityDateHelper # It returns "Upcoming" for upcoming entities # If due date is provided, it returns "# days|weeks|months remaining|ago" # If start date is provided and elapsed, with no due date, it returns "# days elapsed" - def remaining_days_in_words(entity) - start_date = entity.try(:start_date) || entity.try(:[], :start_date) - due_date = entity.try(:due_date) || entity.try(:[], :due_date) - - if due_date && due_date.past? + def remaining_days_in_words(due_date, start_date = nil) + if due_date&.past? content_tag(:strong, 'Past due') - elsif start_date && start_date.future? + elsif start_date&.future? content_tag(:strong, 'Upcoming') elsif due_date is_upcoming = (due_date - Date.today).to_i > 0 @@ -66,7 +63,7 @@ module EntityDateHelper remaining_or_ago = is_upcoming ? _("remaining") : _("ago") "#{content} #{remaining_or_ago}".html_safe - elsif start_date && start_date.past? + elsif start_date&.past? days = (Date.today - start_date).to_i "#{content_tag(:strong, days)} #{'day'.pluralize(days)} elapsed".html_safe end |