Guard against the case days stale can be negative

This commit is contained in:
Matt Rogers 2013-03-10 22:48:27 -05:00
parent d699359648
commit 053e3fc8d6
2 changed files with 16 additions and 1 deletions

View file

@ -3,8 +3,14 @@ require 'active_support/all'
class Staleness
SECONDS_PER_DAY = 86400
def self.days_stale(item, current_user)
return 0 if item.due || item.completed?
return 0 if cannot_be_stale(item, current_user)
(current_user.time - item.created_at).to_i / SECONDS_PER_DAY
end
def self.cannot_be_stale(item, current_user)
return true if item.due || item.completed?
return true if item.created_at > current_user.time
false
end
end