diff options
Diffstat (limited to 'app/models/milestone.rb')
-rw-r--r-- | app/models/milestone.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 9c4476c768e..cbe65d70997 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -27,6 +27,7 @@ class Milestone < ActiveRecord::Base belongs_to :project has_many :issues + has_many :labels, through: :issues has_many :merge_requests has_many :participants, through: :issues, source: :assignee @@ -109,6 +110,19 @@ class Milestone < ActiveRecord::Base 0 end + # Returns the elapsed time (in percent) since the Milestone creation date until today. + # If the Milestone doesn't have a due_date then returns 0 since we can't calculate the elapsed time. + # If the Milestone is overdue then it returns 100%. + def percent_time_used + return 0 unless due_date + return 100 if expired? + + duration = ((created_at - due_date.to_datetime) / 1.day) + days_elapsed = ((created_at - Time.now) / 1.day) + + ((days_elapsed.to_f / duration) * 100).floor + end + def expires_at if due_date if due_date.past? |