From be919a0f62484b9784d4d1a35038239fd2807fa7 Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Thu, 25 Jan 2024 23:07:26 -0600 Subject: [PATCH] Better time formatting --- index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index dc92f26..9d1c759 100644 --- a/index.js +++ b/index.js @@ -55,6 +55,23 @@ function timeFormatter(seconds) { return `${minutes}:${seconds}` } +function gameTimeFormatter(seconds) { + seconds = Math.ceil(seconds) + var minutes = Math.ceil(seconds / 60) + var hours = 0 + if (seconds < 60) { + return 'Under a minute ago' + } else if (minutes < 60) { + return `${minutes} Minutes` + } else { + while (minutes > 60) { + minutes -= 60 + hours += 1 + } + return `${hours} hours and ${minutes} minutes` + } +} + function pageUpdate() { var statuses = { "online": { @@ -230,7 +247,7 @@ function pageUpdate() { Playing ${activity.name}
${activity.details || activity.assets.large_text || " "}
${activity.state || activity.assets.small_text || " "} -
${Math.ceil(((Date.now() - time) / 1000 / 60)).toString() + " Minutes" || " "} +
${gameTimeFormatter((Date.now() - time) / 1000)}