Sha256: 8a82bba0aadd851ea3300afc62ee0092bc0fdbbe86ab5f3509d33cbf5dc075b2

Contents?: true

Size: 676 Bytes

Versions: 1

Compression:

Stored size: 676 Bytes

Contents

module Util
  def self.ago_in_words(time1, time2)
    diff = time1.to_i - time2.to_i
    ago = ''
    if diff == 1
      ago = "#{diff} second ago"
    elsif diff < 60
      ago = "#{diff} seconds ago"
    elsif diff < 120
      ago = "a minute ago"
    elsif diff < 3600
      ago = "#{diff.to_i / 60} minutes ago"
    elsif diff < 7200
      ago = "an hour ago"
    elsif diff < 86400
      ago = "#{diff.to_i / 3600} hours ago"
    elsif diff < 172800
      ago = "yesterday"
    elsif diff < 604800
      ago = "#{diff.to_i / 86400} days ago"
    elsif diff < 1209600
      ago = "last week"
    else
      ago = "#{diff.to_i / 604800} weeks ago"
    end
    ago
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
protolink-0.2.8 example/linkbot/util.rb