mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-15 09:46:19 +01:00
Address PR comments
This commit is contained in:
20
src/tools/parseDuration.ts
Normal file
20
src/tools/parseDuration.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import dayjs from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration';
|
||||
import { TFunction } from 'next-i18next';
|
||||
|
||||
dayjs.extend(duration);
|
||||
|
||||
export const parseDuration = (time: number, t: TFunction): string => {
|
||||
const etaDuration = dayjs.duration(time, 's');
|
||||
|
||||
let eta = etaDuration.format(`s [${t('common:time.seconds')}]`);
|
||||
|
||||
if (etaDuration.asMinutes() > 1) {
|
||||
eta = etaDuration.format(`m [${t('common:time.minutes')}] `) + eta;
|
||||
}
|
||||
if (etaDuration.asHours() > 1) {
|
||||
eta = etaDuration.format(`H [${t('common:time.hours')}] `) + eta;
|
||||
}
|
||||
|
||||
return eta;
|
||||
};
|
||||
Reference in New Issue
Block a user