From 82eb7ddf94e53bf6fa5473abdf1ae4870a4c41ae Mon Sep 17 00:00:00 2001 From: jupiter Date: Sat, 31 Dec 2022 20:02:01 +1100 Subject: [PATCH 1/2] refactor: secondsToDhm() my changes: add plurals if the value is more than 1 do not display `x` if value is 0 previous functionality was "0 days, 1 hours, 3 minutes", now is "1 hour, 3 minutes" --- static/js/pages/profile.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/static/js/pages/profile.js b/static/js/pages/profile.js index 78acca27..2e31d717 100644 --- a/static/js/pages/profile.js +++ b/static/js/pages/profile.js @@ -190,10 +190,17 @@ new Vue({ }, secondsToDhm(seconds) { seconds = Number(seconds); - var dDisplay = `${Math.floor(seconds / (3600 * 24))}d `; - var hDisplay = `${Math.floor(seconds % (3600 * 24) / 3600)}h `; - var mDisplay = `${Math.floor(seconds % 3600 / 60)}m `; - return dDisplay + hDisplay + mDisplay; + let display = ""; + if (Math.floor(seconds / (3600 * 24)) > 0) { + display += `${Math.floor(seconds / (3600 * 24))} day${Math.floor(seconds / (3600 * 24)) > 1 ? "s" : ""}, `; + } + if (Math.floor(seconds % (3600 * 24) / 3600) > 0) { + display += `${Math.floor(seconds % (3600 * 24) / 3600)} hour${Math.floor(seconds % (3600 * 24) / 3600) > 1 ? "s" : ""}, `; + } + if (Math.floor(seconds % 3600 / 60) > 0) { + display += `${Math.floor(seconds % 3600 / 60)} minute${Math.floor(seconds % 3600 / 60) > 1 ? "s" : ""}`; + } + return display; }, StrtoGulagInt() { switch (this.mode + "|" + this.mods) { From d017662414834ae42dc5ef6ef9b895fc18e9aaf7 Mon Sep 17 00:00:00 2001 From: jupiter Date: Sat, 31 Dec 2022 20:18:15 +1100 Subject: [PATCH 2/2] fix: add string if user hasn't played at all (and thus, can't have playtime) --- static/js/pages/profile.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/static/js/pages/profile.js b/static/js/pages/profile.js index 2e31d717..a65c2c18 100644 --- a/static/js/pages/profile.js +++ b/static/js/pages/profile.js @@ -199,6 +199,8 @@ new Vue({ } if (Math.floor(seconds % 3600 / 60) > 0) { display += `${Math.floor(seconds % 3600 / 60)} minute${Math.floor(seconds % 3600 / 60) > 1 ? "s" : ""}`; + } else { + display = "less than a minute"; } return display; },