From d4a279d2f4540f4be0cd7c5cf11dcc096c45ccae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Vigh?= Date: Fri, 21 May 2021 11:51:47 +0200 Subject: [PATCH] MAPG-235 refactored human readable time format --- public/static/js/maps.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/public/static/js/maps.js b/public/static/js/maps.js index 41c16ae..35c4e33 100644 --- a/public/static/js/maps.js +++ b/public/static/js/maps.js @@ -67,17 +67,27 @@ var Util = { printTimeForHuman: function (time) { - if (time < 60) { - return '' + time + ' seconds'; - } else if (time == 60) { - return '1 minute'; - } else if (time % 60 == 0) { - return '' + Math.floor(time / 60) + ' minutes'; - } else if (time % 60 == 1) { - return '' + Math.floor(time / 60) + ' minutes and 1 second'; - } else { - return '' + Math.floor(time / 60) + ' minutes and ' + time % 60 + ' seconds'; + const minutes = Math.floor(time / 60); + const seconds = time % 60; + var time_str = ''; + + if (minutes == 1) { + time_str += '1 minute'; + } else if (minutes > 1) { + time_str += minutes + ' minutes'; } + + 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; } };