mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-19 05:38:08 +01:00
Guard against the case days stale can be negative
This commit is contained in:
parent
d699359648
commit
053e3fc8d6
2 changed files with 16 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue