fix: 时间展示修复
This commit is contained in:
@@ -1,41 +1,13 @@
|
||||
import Taro from "@tarojs/taro";
|
||||
import dayjs, { Dayjs } from "dayjs";
|
||||
import "dayjs/locale/zh-cn";
|
||||
import { calculateDistance } from "@/utils";
|
||||
import { calculateDistance, genGameLength } from "@/utils";
|
||||
import { View, Image, Text, Map } from "@tarojs/components";
|
||||
import img from "@/config/images";
|
||||
import styles from "./index.module.scss";
|
||||
|
||||
dayjs.locale("zh-cn");
|
||||
|
||||
function genGameLength(startTime: Dayjs, endTime: Dayjs) {
|
||||
if (!startTime || !endTime) {
|
||||
return "";
|
||||
}
|
||||
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}小时`;
|
||||
}
|
||||
|
||||
// 如果是整数小时,不显示小数点
|
||||
if (Number.isInteger(totalHours)) {
|
||||
return `${totalHours}小时`;
|
||||
}
|
||||
// 保留一位小数,去除末尾的0
|
||||
return `${parseFloat(totalHours.toFixed(1))}小时`;
|
||||
}
|
||||
|
||||
function genGameRange(startTime: Dayjs, endTime: Dayjs) {
|
||||
if (!startTime || !endTime) {
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user