fix: 修改以支持非整数小时数
This commit is contained in:
@@ -12,14 +12,28 @@ function genGameLength(startTime: Dayjs, endTime: Dayjs) {
|
|||||||
if (!startTime || !endTime) {
|
if (!startTime || !endTime) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
const hours = endTime.diff(startTime, "hour");
|
const totalMinutes = endTime.diff(startTime, "minute");
|
||||||
if (Math.floor(hours / 24) >= 1) {
|
const totalHours = totalMinutes / 60;
|
||||||
const leftHours = Math.floor(hours % 24);
|
|
||||||
return `${Math.floor(hours / 24)}天${
|
if (totalHours >= 24) {
|
||||||
leftHours !== 0 ? `${leftHours}小时` : ""
|
const days = Math.floor(totalHours / 24);
|
||||||
}`;
|
const remainingHours = totalHours % 24;
|
||||||
|
|
||||||
|
if (remainingHours === 0) {
|
||||||
|
return `${days}天`;
|
||||||
}
|
}
|
||||||
return `${hours}小时`;
|
|
||||||
|
// 保留一位小数
|
||||||
|
const displayHours = parseFloat(remainingHours.toFixed(1));
|
||||||
|
return `${days}天${displayHours}小时`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是整数小时,不显示小数点
|
||||||
|
if (Number.isInteger(totalHours)) {
|
||||||
|
return `${totalHours}小时`;
|
||||||
|
}
|
||||||
|
// 保留一位小数,去除末尾的0
|
||||||
|
return `${parseFloat(totalHours.toFixed(1))}小时`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genGameRange(startTime: Dayjs, endTime: Dayjs) {
|
function genGameRange(startTime: Dayjs, endTime: Dayjs) {
|
||||||
|
|||||||
Reference in New Issue
Block a user