diff --git a/cista-front/src/utils/index.ts b/cista-front/src/utils/index.ts index 6771273..6954948 100644 --- a/cista-front/src/utils/index.ts +++ b/cista-front/src/utils/index.ts @@ -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',