dateformat code cleanup
This commit is contained in:
parent
4c7b310f82
commit
dd1d85f412
|
@ -22,26 +22,21 @@ export function formatUnixDate(t: number) {
|
|||
const date = new Date(t * 1000)
|
||||
const now = new Date()
|
||||
const diff = date.getTime() - now.getTime()
|
||||
const adiff = Math.abs(diff)
|
||||
const formatter = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
|
||||
if (Math.abs(diff) <= 5000) {
|
||||
return 'now'
|
||||
}
|
||||
if (Math.abs(diff) <= 60000) {
|
||||
if (adiff <= 5000) return 'now'
|
||||
if (adiff <= 60000) {
|
||||
return formatter.format(Math.round(diff / 1000), 'second').replace(' ago', '').replaceAll(' ', '\u202F')
|
||||
}
|
||||
|
||||
if (Math.abs(diff) <= 3600000) {
|
||||
if (adiff <= 3600000) {
|
||||
return formatter.format(Math.round(diff / 60000), 'minute').replace('utes', '').replace('ute', '').replaceAll(' ', '\u202F')
|
||||
}
|
||||
|
||||
if (Math.abs(diff) <= 86400000) {
|
||||
if (adiff <= 86400000) {
|
||||
return formatter.format(Math.round(diff / 3600000), 'hour').replaceAll(' ', '\u202F')
|
||||
}
|
||||
|
||||
if (Math.abs(diff) <= 604800000) {
|
||||
if (adiff <= 604800000) {
|
||||
return formatter.format(Math.round(diff / 86400000), 'day').replaceAll(' ', '\u202F')
|
||||
}
|
||||
|
||||
let d = date.toLocaleDateString('en-ie', {
|
||||
weekday: 'short',
|
||||
year: 'numeric',
|
||||
|
|
Loading…
Reference in New Issue
Block a user