module TimeHelper
  def self.ago(time)
    seconds = Time.now - time
    
    days = (seconds / 86400).to_i
    hours = ((seconds % 86400) / 3600).to_i
    minutes = ((seconds % 3600) / 60).to_i
    secs = (seconds % 60).to_i
    
    parts = []
    parts << "#{days} day#{'s' if days != 1}" if days > 0
    parts << "#{hours} hour#{'s' if hours != 1}" if hours > 0
    parts << "#{minutes} minute#{'s' if minutes != 1}" if minutes > 0
    parts << "#{secs} second#{'s' if secs != 1}" if secs > 0 || parts.empty?
    
    parts.join(", and ") + " ago"
  end
end