mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Fix plurals in prettyDate()
This commit is contained in:
parent
e98baf062a
commit
6193f452c3
1 changed files with 9 additions and 6 deletions
15
src/utils.js
15
src/utils.js
|
|
@ -42,22 +42,25 @@ export const parse = text => markdown.render(text.replaceAll('<', '<').replac
|
|||
// UTC to "Reddit time format" (e.g. 5 hours ago, just now, etc...)
|
||||
export const prettyDate = createdUTC => {
|
||||
const currentUTC = Math.floor((new Date()).getTime() / 1000)
|
||||
const secondDiff = currentUTC - createdUTC
|
||||
const dayDiff = Math.floor(secondDiff / 86400)
|
||||
|
||||
if (dayDiff < 0) return ''
|
||||
if (dayDiff === 0) {
|
||||
const secondDiff = currentUTC - createdUTC
|
||||
if (secondDiff < 86400) {
|
||||
if (secondDiff < 10) return 'just now'
|
||||
if (secondDiff < 60) return `${secondDiff} seconds ago`
|
||||
if (secondDiff < 120) return 'a minute ago'
|
||||
if (secondDiff < 3600) return `${Math.floor(secondDiff / 60)} minutes ago`
|
||||
if (secondDiff < 7200) return 'an hour ago'
|
||||
if (secondDiff < 86400) return `${Math.floor(secondDiff / 3600)} hours ago`
|
||||
return `${Math.floor(secondDiff / 3600)} hours ago`
|
||||
}
|
||||
if (dayDiff < 2) return `1 day ago`
|
||||
|
||||
const dayDiff = Math.floor(secondDiff / 86400)
|
||||
if (dayDiff < 2) return '1 day ago'
|
||||
if (dayDiff < 7) return `${dayDiff} days ago`
|
||||
if (dayDiff < 14) return '1 week ago'
|
||||
if (dayDiff < 31) return `${Math.floor(dayDiff / 7)} weeks ago`
|
||||
if (dayDiff < 60) return '1 month ago'
|
||||
if (dayDiff < 365) return `${Math.floor(dayDiff / 30)} months ago`
|
||||
if (dayDiff < 730) return '1 year ago'
|
||||
return `${Math.floor(dayDiff / 365)} years ago`
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue