mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-18 03:25:31 -05:00
20 lines
No EOL
454 B
Ruby
20 lines
No EOL
454 B
Ruby
module AgeWords
|
|
|
|
def self.age_words(secs)
|
|
return "—" if secs.blank?
|
|
|
|
mins = (secs / 60.0)
|
|
hours = (mins / 60.0)
|
|
days = (hours / 24.0)
|
|
months = (days / 30.0)
|
|
years = (months / 12.0)
|
|
|
|
return "#{years.floor}y" if years > 1
|
|
return "#{months.floor}mo" if months > 1
|
|
return "#{days.floor}d" if days > 1
|
|
return "#{hours.floor}h" if hours > 1
|
|
return "< 1m" if mins < 1
|
|
return "#{mins.floor}m"
|
|
end
|
|
|
|
end |