Created
February 24, 2014 10:54
-
-
Save emad-elsaid/9185583 to your computer and use it in GitHub Desktop.
age in seconds, minutes, hours, days and auto update
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
require 'time' | |
Date_of_birth = '1988-8-31' | |
# Credit to : http://stackoverflow.com/questions/4136248/how-to-generate-a-human-readable-time-range-using-ruby-on-rails | |
# and modified a little bit | |
def humanize secs | |
[ | |
[60, :seconds], | |
[60, :minutes], | |
[24, :hours], | |
[365, :days], | |
[100, :years] | |
].map do |count, name| | |
if secs > 0 | |
secs, n = secs.divmod(count) | |
"#{n.to_i} #{name}" | |
end | |
end.compact.reverse.join(' ') | |
end | |
loop do | |
distance = Time.new - Time.parse(Date_of_birth) | |
print humanize(distance)+"\r" | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
your script inspired me >>
Thanks Emad :)
https://gist.github.com/Ahmed-Fawzy/6351ef65788987acaa7a