From dd1d85f4124af461233d184fc65f8f2089e93648 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Mon, 6 Nov 2023 11:38:11 +0000 Subject: [PATCH] dateformat code cleanup --- cista-front/src/utils/index.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) 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',