Browse Source

chore: 优化运行时长显示

pull/191/head
cp3hnu 10 months ago
parent
commit
d35b717307
1 changed files with 14 additions and 6 deletions
  1. +14
    -6
      react-ui/src/utils/date.ts

+ 14
- 6
react-ui/src/utils/date.ts View File

@@ -29,22 +29,30 @@ export const elapsedTime = (begin?: string | null, end?: string | null): string
const hours = duration.hours();
const minutes = duration.minutes();
const seconds = duration.seconds();
const elspsedArray = [];
if (years !== 0) {
return `${years}年${months}个月`;
elspsedArray.push(`${years}年`);
}
if (months !== 0) {
return `${months}个月${days}天`;
elspsedArray.push(`${months}个月`);
}
if (days !== 0) {
return `${days}天${hours}小时`;
elspsedArray.push(`${days}天`);
}
if (hours !== 0) {
return `${hours}小时${minutes}分`;
elspsedArray.push(`${hours}小时`);
}
if (minutes !== 0) {
return `${minutes}分${seconds}秒`;
elspsedArray.push(`${minutes}分`);
}
return `${seconds}秒`;
if (seconds !== 0) {
elspsedArray.push(`${seconds}秒`);
}

if (elspsedArray.length === 0) {
return '0秒';
}
return elspsedArray.slice(0, 2).join('');
};

/**


Loading…
Cancel
Save