Created
October 6, 2016 21:20
-
-
Save h00s/b863579ec9c7b8c65311e6862298b7a0 to your computer and use it in GitHub Desktop.
This file contains 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
def time_ago_in_words(seconds) do | |
minutes = round(seconds/60) | |
case minutes do | |
minutes when minutes in 0..1 -> | |
case seconds do | |
seconds when seconds in 0..4 -> | |
"less than 5 seconds" | |
seconds when seconds in 5..9 -> | |
"less than 10 seconds" | |
seconds when seconds in 10..19 -> | |
"less than 20 seconds" | |
seconds when seconds in 20..39 -> | |
"half a minute" | |
seconds when seconds in 40..59 -> | |
"less than 1 minute" | |
_ -> | |
"1 minute" | |
end | |
minutes when minutes in 2..44 -> | |
"#{minutes} minutes" | |
minutes when minutes in 45..89 -> | |
"about 1 hour" | |
minutes when minutes in 90..1439 -> | |
"about #{round(minutes/60)} hours" | |
minutes when minutes in 1440..2519 -> | |
"1 day" | |
minutes when minutes in 2520..43199 -> | |
"#{round(minutes/1440)} days" | |
minutes when minutes in 43200..86399 -> | |
"about 1 month" | |
minutes when minutes in 86400..525599 -> | |
"#{round(minutes/43200)} months" | |
minutes when minutes in 525600..1051199 -> | |
"1 year" | |
_ -> | |
"#{round(minutes/525600)} years" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment