diff --git a/src/game_pages/detail/components/GameInfo/index.tsx b/src/game_pages/detail/components/GameInfo/index.tsx index 1d2075b..6a967b2 100644 --- a/src/game_pages/detail/components/GameInfo/index.tsx +++ b/src/game_pages/detail/components/GameInfo/index.tsx @@ -12,14 +12,28 @@ function genGameLength(startTime: Dayjs, endTime: Dayjs) { if (!startTime || !endTime) { return ""; } - const hours = endTime.diff(startTime, "hour"); - if (Math.floor(hours / 24) >= 1) { - const leftHours = Math.floor(hours % 24); - return `${Math.floor(hours / 24)}天${ - leftHours !== 0 ? `${leftHours}小时` : "" - }`; + const totalMinutes = endTime.diff(startTime, "minute"); + const totalHours = totalMinutes / 60; + + if (totalHours >= 24) { + const days = Math.floor(totalHours / 24); + const remainingHours = totalHours % 24; + + if (remainingHours === 0) { + return `${days}天`; + } + + // 保留一位小数 + const displayHours = parseFloat(remainingHours.toFixed(1)); + return `${days}天${displayHours}小时`; } - return `${hours}小时`; + + // 如果是整数小时,不显示小数点 + if (Number.isInteger(totalHours)) { + return `${totalHours}小时`; + } + // 保留一位小数,去除末尾的0 + return `${parseFloat(totalHours.toFixed(1))}小时`; } function genGameRange(startTime: Dayjs, endTime: Dayjs) {