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 {
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
You can’t perform that action at this time.
0 commit comments