🐞 fix: 修正时间统计错误
This commit is contained in:
parent
70e7fa534f
commit
777979f0e3
@ -43,12 +43,16 @@ export const getTimeCapsule = () => {
|
|||||||
// 获取当前时间单位的结束时间
|
// 获取当前时间单位的结束时间
|
||||||
const end = now.endOf(unit);
|
const end = now.endOf(unit);
|
||||||
// 计算总的天数或小时数
|
// 计算总的天数或小时数
|
||||||
const total = Math.floor(end.diff(start, unit === "day" ? "hour" : "day")) + 1;
|
const total = end.diff(start, unit === "day" ? "hour" : "day") + 1;
|
||||||
// 计算已经过去的天数或小时数
|
// 计算已经过去的天数或小时数
|
||||||
const passed = Math.floor(now.diff(start, unit === "day" ? "hour" : "day"));
|
let passed;
|
||||||
// 计算剩余的天数或小时数
|
if (unit === "week" && now.day() === 0) {
|
||||||
|
// 如果是星期日
|
||||||
|
passed = total - 1;
|
||||||
|
} else {
|
||||||
|
passed = now.diff(start, unit === "day" ? "hour" : "day");
|
||||||
|
}
|
||||||
const remaining = total - passed;
|
const remaining = total - passed;
|
||||||
// 计算已经过去的时间占总时间的百分比
|
|
||||||
const percentage = (passed / total) * 100;
|
const percentage = (passed / total) * 100;
|
||||||
// 返回数据
|
// 返回数据
|
||||||
return {
|
return {
|
||||||
@ -56,7 +60,7 @@ export const getTimeCapsule = () => {
|
|||||||
total: total,
|
total: total,
|
||||||
passed: passed,
|
passed: passed,
|
||||||
remaining: remaining,
|
remaining: remaining,
|
||||||
percentage: Number(percentage.toFixed(2)),
|
percentage: percentage.toFixed(2),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user