From cb2e5ee557a0db857799ceef4ba6624a9238ff69 Mon Sep 17 00:00:00 2001 From: alekswilc Date: Tue, 27 Aug 2024 20:31:31 +0200 Subject: [PATCH] (ench): Change manual time formatting to dayjs time fomatting. See #38 --- src/util/time.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/util/time.ts b/src/util/time.ts index 6b93a3e..11ed332 100644 --- a/src/util/time.ts +++ b/src/util/time.ts @@ -13,18 +13,8 @@ dayjs.locale(pl); export const msToTime = (duration: number, long = false) => { const time = dayjs.duration(duration, 'milliseconds'); - if (long) { - let t = ''; - if (time.days()) t+= `${time.days()}d `; - if (time.hours()) t+= `${time.hours()}h `; - if (time.minutes()) t+= `${time.minutes()}m `; - if (time.seconds()) t+= `${time.seconds()}s`; - - if (!t) t = '1s'; - - return `${time.humanize()} (${t})`; - } - + if (long) + return `${time.humanize()} (${time.format('Y[y] M[mth] D[d] H[h] m[m] s[s]').split(' ').map(x => x.split('')[0] === '0' ? null : x).filter(x => x).join(' ')})`; return time.humanize(); } \ No newline at end of file