Merge pull request 'Change manual time formatting to dayjs time fomatting.' (#39) from dev into main

Reviewed-on: alekswilc/simrail-logs#39
Reviewed-by: Aleksander Wilczyński <aleks@alekswilc.dev>
This commit is contained in:
Aleksander Wilczyński 2024-08-27 20:37:52 +02:00
commit f29c310cd3
Signed by: gitea
GPG Key ID: CECFC30736A3D1C8

View File

@ -13,16 +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`;
return `${time.humanize()} (${t})`;
}
return time.humanize(); return time.humanize();
} }