Round "removed(?) from archive" times down

This commit is contained in:
Christopher Gurnee 2021-11-01 16:14:05 -04:00
parent 16d665228a
commit 157fd7104f
2 changed files with 6 additions and 5 deletions

View file

@ -27,7 +27,7 @@ const Comment = (props) => {
else if (props.hasOwnProperty('retrieved_utc')) {
innerHTML = `<p>[removed within ${prettyTimeDiff(props.retrieved_utc - props.created_utc)}]</p>`
} else {
innerHTML = `<p>[either removed too quickly, or <a href='https://www.reddit.com/r/pushshift/comments/pgzdav/the_api_now_appears_to_rewrite_nearly_all/'>removed(?) from archive</a> after ${prettyTimeDiff(props.retrieved_on - props.created_utc)}]</p>`
innerHTML = `<p>[either removed too quickly, or <a href='https://www.reddit.com/r/pushshift/comments/pgzdav/the_api_now_appears_to_rewrite_nearly_all/'>removed(?) from archive</a> after ${prettyTimeDiff(props.retrieved_on - props.created_utc, true)}]</p>`
}
} else {
innerHTML = parse(props.body)

View file

@ -51,12 +51,13 @@ export const prettyDate = createdUTC => {
}
// Time difference in seconds to text, rounded up (e.g. x seconds/minutes/hours)
export const prettyTimeDiff = secondDiff => {
export const prettyTimeDiff = (secondDiff, roundDown = false) => {
if (secondDiff < 2) return `1 second`
if (secondDiff < 120) return `${secondDiff} seconds`
if (secondDiff < 7200) return `${Math.ceil(secondDiff / 60)} minutes`
if (secondDiff < 172800) return `${Math.ceil(secondDiff / 3600)} hours`
return `${Math.ceil(secondDiff / 86400)} days`
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`
}
// Reddit format for scores, e.g. 12000 => 12k