Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit f616670

Browse files
committed
🐞 fix: 修复时间胶囊周计算错误
1 parent 7ecc902 commit f616670

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/utils/getTime.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ export const getTimeCapsule = () => {
4545
// 计算总的天数或小时数
4646
const total = end.diff(start, unit === "day" ? "hour" : "day") + 1;
4747
// 计算已经过去的天数或小时数
48-
let passed;
49-
if (unit === "week" && now.day() === 0) {
50-
// 如果是星期日
51-
passed = total - 1;
52-
} else {
53-
passed = now.diff(start, unit === "day" ? "hour" : "day");
48+
let passed = now.diff(start, unit === "day" ? "hour" : "day");
49+
if (unit === "week") {
50+
passed = (passed + 6) % 7;
5451
}
5552
const remaining = total - passed;
5653
const percentage = (passed / total) * 100;

0 commit comments

Comments
 (0)