summaryrefslogtreecommitdiff
path: root/public/javascripts/util.js
blob: 9c2fff4ff813fab8f3540e6fd8303d9d65a1a477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function pluralize (n, s) {
	return n + " " + (n == 1 ? s : s + "s");
}
function toTime (time) {
	var str = [];
	if (time > 86400) {
		str.push( pluralize( Math.floor(time / 86400), "day" ) );
	}
	if (time > 3600) {
		str.push( pluralize( Math.floor(time / 3600) % 24, "hour" ) );
	}
	if (time > 60) {
		str.push( pluralize( Math.floor(time / 60) % 60, "minute" ) );
	}
	str.push( pluralize( Math.floor(10 * (time % 60)) / 10, "second" ) );
	return str.join(", ");
}