Created
June 6, 2017 00:00
-
-
Save radavis/4a775fd0298340e43433b219f49b8529 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TimeHelper | |
def now | |
Time.new.to_i | |
end | |
def time_ago(seconds, now = Time.now.to_i) | |
minutes = (now - seconds) / 60 | |
quantity = [minutes / 525600, minutes / 43200, minutes / 1440, minutes / 60, minutes] | |
%w(year month day hour minute).each_with_index do |type, i| | |
q = quantity[i] | |
if type == "minute" && q < 2 | |
return "just now" | |
elsif q > 0 | |
return "#{q} #{type}#{ q == 1 ? "" : "s" } ago" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment