File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -53,19 +53,27 @@ export class StorageService {
53
53
static getStats ( ) : MasturbationStats {
54
54
const records = this . getRecords ( ) ;
55
55
const now = new Date ( ) ;
56
+
57
+ // 计算本周开始时间(过去7天)
56
58
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
+
59
65
const totalCount = records . length ;
60
66
const totalDuration = records . reduce ( ( sum , record ) => sum + record . duration , 0 ) ;
61
67
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
+
64
72
return {
65
73
totalCount,
66
74
averageDuration : totalCount > 0 ? totalDuration / totalCount : 0 ,
67
75
frequencyPerWeek : recordsLastWeek . length ,
68
- frequencyPerMonth : recordsLastMonth . length
76
+ frequencyPerMonth : recordsCurrentMonth . length
69
77
} ;
70
78
}
71
79
You can’t perform that action at this time.
0 commit comments