feat: 看板通话时长格式化hms

This commit is contained in:
TsMask
2024-01-30 17:18:20 +08:00
parent a654680192
commit 41335ae99c
2 changed files with 25 additions and 1 deletions

View File

@@ -73,6 +73,29 @@ export function diffValue(
return value;
}
/**
* 格式化秒值为 ?h?m?s
* @param seconds 2558 秒
* @returns 1h42m38s
*/
export function parseDuration(seconds: number | string) {
seconds = Number(seconds) || 0;
const duration = dayjs().startOf('day').subtract(seconds, 'seconds');
const secondsLeft = duration.format('s');
const minutes = duration.format('m');
const hours = duration.format('H');
if (+hours > 0) {
return `${hours}h${minutes}m${secondsLeft}s`;
}
if (+minutes > 0) {
return `${minutes}m${secondsLeft}s`;
}
if (+secondsLeft > 0) {
return `${secondsLeft}s`;
}
return `${seconds}s`;
}
/**
* 格式时间不带年份
*