Skip to content

Instantly share code, notes, and snippets.

@sillyfellow
Last active May 9, 2016 12:50
Show Gist options
  • Save sillyfellow/41eb689e7010a6bda428b2002f337381 to your computer and use it in GitHub Desktop.
Save sillyfellow/41eb689e7010a6bda428b2002f337381 to your computer and use it in GitHub Desktop.
Poor man's descriptive time stuff
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