From 917d6a8c19d93e966652f7447577967d97b3f4fd Mon Sep 17 00:00:00 2001 From: Sophie Mondzelewski Date: Tue, 5 Jul 2022 11:55:42 -0500 Subject: [PATCH] Move uptime to a file, This is partially for logging --- functions/uptime.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 functions/uptime.js diff --git a/functions/uptime.js b/functions/uptime.js new file mode 100644 index 0000000..b10b8cf --- /dev/null +++ b/functions/uptime.js @@ -0,0 +1,17 @@ +module.exports = () => { + const tSeconds = process.uptime(); + + const tDays = parseInt(tSeconds / 86400); + const tHrs = parseInt((tSeconds % 86400) / 3600); + const tMins = parseInt((tSeconds % 3600) / 60); + const tSecs = parseInt(tSeconds % 60); + // We can probably just return tSeconds (totalSeconds) instead of parsing. + // So that was a fucking lie. + + const days = tDays + (tDays === 1 ? ' day' : ' days'); + const hours = tHrs + (tHrs === 1 ? ' hour' : ' hours'); + const minutes = tMins + (tMins === 1 ? ' minute' : ' hours'); + const seconds = tSecs + (tSecs === 1 ? ' second' : ' seconds'); + + return `${days}, ${hours}, ${minutes}, ${seconds}`; +};