Skip to content

Commit 3d933bb

Browse files
committed
修复历史记录当中,当月记录无法正常显示的bug,此前逻辑为计算最近30天打胶记录
1 parent 50920e9 commit 3d933bb

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/services/storage.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,27 @@ export class StorageService {
5353
static getStats(): MasturbationStats {
5454
const records = this.getRecords();
5555
const now = new Date();
56+
57+
// 计算本周开始时间(过去7天)
5658
const oneWeekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
57-
const oneMonthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
58-
59+
60+
// 计算本月开始时间(当月1号)
61+
const currentMonthStart = new Date(now.getFullYear(), now.getMonth(), 1);
62+
63+
// 计算过去30天的开始时间(用于保持原有的frequencyPerMonth兼容性)
64+
5965
const totalCount = records.length;
6066
const totalDuration = records.reduce((sum, record) => sum + record.duration, 0);
6167
const recordsLastWeek = records.filter(record => record.startTime >= oneWeekAgo);
62-
const recordsLastMonth = records.filter(record => record.startTime >= oneMonthAgo);
63-
68+
69+
// 修改为使用当月1号作为过滤条件
70+
const recordsCurrentMonth = records.filter(record => record.startTime >= currentMonthStart);
71+
6472
return {
6573
totalCount,
6674
averageDuration: totalCount > 0 ? totalDuration / totalCount : 0,
6775
frequencyPerWeek: recordsLastWeek.length,
68-
frequencyPerMonth: recordsLastMonth.length
76+
frequencyPerMonth: recordsCurrentMonth.length
6977
};
7078
}
7179

0 commit comments

Comments
 (0)