X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Futils%2Fdatetime.js;h=5f75f6de3345c8f0f2556b2a5e1692e3431313a5;hb=2bb4666e276e837add0958554a11b38f7f4d9357;hp=75e85d714baa073efc0bc347a566a918d18b5d0b;hpb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;p=vchess.git diff --git a/client/src/utils/datetime.js b/client/src/utils/datetime.js index 75e85d71..5f75f6de 100644 --- a/client/src/utils/datetime.js +++ b/client/src/utils/datetime.js @@ -31,20 +31,21 @@ export function ppt(t) { // "Pretty print" an amount of time given in seconds const dayInSeconds = 60 * 60 * 24; const hourInSeconds = 60 * 60; - const days = Math.floor(t / dayInSeconds); + let days = Math.floor(t / dayInSeconds); const hours = Math.floor((t % dayInSeconds) / hourInSeconds); const minutes = Math.floor((t % hourInSeconds) / 60); const seconds = Math.floor(t % 60); let res = ""; + // NOTE: 3 days limit is rather arbitrary + if (days >= 3 && hours >= 12) days++; if (days > 0) res += days + "d "; - if (days <= 3 && hours > 0) - //NOTE: 3 is arbitrary - res += hours + "h "; + if (days < 3 && hours > 0) res += hours + "h "; if (days == 0 && minutes > 0) res += hours > 0 ? padDigits(minutes) + "m " : minutes + ":"; if (days == 0 && hours == 0) { res += padDigits(seconds); - if (minutes == 0) res += "s"; //seconds indicator, since this is the only number printed + // Seconds indicator, since this is the only number printed: + if (minutes == 0) res += "s"; } return res.trim(); //remove potential last space }