From f7dc5a76fe0618b0c091aba3b76ad989715f0816 Mon Sep 17 00:00:00 2001 From: Christopher Gurnee Date: Sun, 14 Nov 2021 09:21:00 -0500 Subject: [PATCH] Add hours to 'removed from archive after X days' --- src/utils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 4a38061..544d796 100644 --- a/src/utils.js +++ b/src/utils.js @@ -66,14 +66,16 @@ export const prettyDate = createdUTC => { return `${Math.floor(dayDiff / 365)} years ago` } -// Time difference in seconds to text, rounded up (e.g. x seconds/minutes/hours) +// Time difference in seconds to text, rounded up by default (e.g. x seconds/minutes/hours) export const prettyTimeDiff = (secondDiff, roundDown = false) => { if (secondDiff < 2) return `1 second` if (secondDiff < 120) return `${secondDiff} seconds` const round = roundDown ? Math.floor : Math.ceil if (secondDiff < 7200) return `${round(secondDiff / 60)} minutes` if (secondDiff < 172800) return `${round(secondDiff / 3600)} hours` - return `${round(secondDiff / 86400)} days` + const days = round(secondDiff / 86400) + if (days < 10 && roundDown) return `${days} days, ${round((secondDiff - days*86400) / 3600)} hours` + return `${days} days` } // Reddit format for scores, e.g. 12000 => 12k