Detect-It-Easy/db/duration
2024-04-06 18:32:56 +03:00

14 lines
No EOL
454 B
Text
Executable file

// Convert a time in seconds to a string:
// less than 10 seconds: N.NNs
// less than a minute: NN.Ns
// otherwise: NmNNs
// Author: Jason Hood <jadoxa@yahoo.com.au>
function duration(nSeconds) {
if (nSeconds < 60) {
return nSeconds.toFixed(nSeconds < 10 ? 2 : 1) + "s";
}
nSeconds = Math.round(nSeconds);
return Math.floor(nSeconds / 60) + "m" +
("0" + Math.floor(nSeconds % 60)).slice(-2) + "s";
}