1
0
Fork 0
shezmu/dashboard/js/format.js

19 lines
560 B
JavaScript
Raw Normal View History

2015-10-28 19:37:17 +00:00
function formatDuration(dur) {
if (dur < 10) {
2015-10-31 20:52:58 +00:00
return "" + dur.toFixed(3) + "ms";
2015-10-28 19:37:17 +00:00
} else if (dur < 100) {
2015-10-31 20:52:58 +00:00
return "" + dur.toFixed(2) + "ms";
2015-10-28 19:37:17 +00:00
} else if (dur < 1000) {
2015-10-31 20:52:58 +00:00
return "" + dur.toFixed(1) + "ms";
2015-10-28 19:37:17 +00:00
} else if (dur < 10000) {
2015-10-31 20:52:58 +00:00
return "" + (dur / 1000).toFixed(3) + "s";
2015-10-28 19:37:17 +00:00
} else if (dur < 60000) {
2015-10-31 20:52:58 +00:00
return "" + (dur / 1000).toFixed(2) + "s";
2015-10-28 19:37:17 +00:00
} else {
2015-10-31 20:52:58 +00:00
dur = Math.ceil(dur / 1000);
2015-10-28 19:37:17 +00:00
var m = Math.floor(dur / 60);
var s = dur % 60;
return "" + m + "m" + s + "s";
}
}