MAPG-235 refactored human readable time format

This commit is contained in:
Balázs Vigh 2021-05-21 11:51:47 +02:00
parent aadeda05af
commit d4a279d2f4

View File

@ -67,17 +67,27 @@
var Util = { var Util = {
printTimeForHuman: function (time) { printTimeForHuman: function (time) {
if (time < 60) { const minutes = Math.floor(time / 60);
return '' + time + ' seconds'; const seconds = time % 60;
} else if (time == 60) { var time_str = '';
return '1 minute';
} else if (time % 60 == 0) { if (minutes == 1) {
return '' + Math.floor(time / 60) + ' minutes'; time_str += '1 minute';
} else if (time % 60 == 1) { } else if (minutes > 1) {
return '' + Math.floor(time / 60) + ' minutes and 1 second'; time_str += minutes + ' minutes';
} else {
return '' + Math.floor(time / 60) + ' minutes and ' + time % 60 + ' seconds';
} }
if (minutes > 0 && seconds > 0) {
time_str += ' and ';
}
if (seconds == 1) {
time_str += '1 second';
} else if (seconds > 1) {
time_str += seconds + ' seconds';
}
return time_str;
} }
}; };