Change manual time formatting to dayjs time fomatting. #39

Merged
alekswilc merged 5 commits from dev into main 2024-08-27 20:37:53 +02:00
Showing only changes of commit cb2e5ee557 - Show all commits

View File

@ -13,18 +13,8 @@ dayjs.locale(pl);
export const msToTime = (duration: number, long = false) => { export const msToTime = (duration: number, long = false) => {
const time = dayjs.duration(duration, 'milliseconds'); const time = dayjs.duration(duration, 'milliseconds');
if (long) { if (long)
let t = ''; 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(' ')})`;
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})`;
}
return time.humanize(); return time.humanize();
} }