1
0
Fork 0

Add js duration format helper

This commit is contained in:
Gregory Eremin 2015-10-28 22:37:17 +03:00
parent 4edd072a56
commit 663eca857f
1 changed files with 18 additions and 0 deletions

18
dashboard/js/format.js Normal file
View File

@ -0,0 +1,18 @@
function formatDuration(dur) {
if (dur < 10) {
return "" + dur + "ms";
} else if (dur < 100) {
return "" + dur.toFixed(5) + "ms";
} else if (dur < 1000) {
return "" + dur.toFixed(4) + "ms";
} else if (dur < 10000) {
return "" + (dur / 1000).toFixed(6) + "s";
} else if (dur < 60000) {
return "" + (dur / 1000).toFixed(5) + "s";
} else {
dur = Math.round(dur / 1000);
var m = Math.floor(dur / 60);
var s = dur % 60;
return "" + m + "m" + s + "s";
}
}