Last active
May 9, 2016 12:50
-
-
Save sillyfellow/41eb689e7010a6bda428b2002f337381 to your computer and use it in GitHub Desktop.
Poor man's descriptive time stuff
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
function pluralize(count, name) { | |
var suffix = (count == 1) ? "" : "s" | |
return count + name + suffix | |
}; | |
function secondsToDescriptiveTime(seconds) { | |
var DAYCOUNT = 86400 | |
var HOURCOUNT = 3600 | |
var MINUTECOUNT = 60 | |
if (seconds > DAYCOUNT) { | |
days = Math.round(seconds / DAYCOUNT ) | |
return pluralize(days, " Day") | |
} | |
if (seconds > HOURCOUNT) { | |
hours = Math.round(seconds / HOURCOUNT ) | |
return pluralize(hours, " Hour") | |
} | |
if (seconds > MINUTECOUNT) { | |
minutes = Math.round(seconds / MINUTECOUNT) | |
return pluralize(minutes, " Minute") | |
} | |
return pluralize(seconds, " Second") | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment