fix:修复本周从七天开始的bug改为从周一开始

This commit is contained in:
Free-sss 2025-09-02 19:55:30 +08:00
parent 600b27aa5c
commit ba95104bea
2 changed files with 8 additions and 4 deletions

View File

@ -143,9 +143,11 @@ function generateTimeRange(period: string): { startTime: string; endTime: string
startTime.setHours(0, 0, 0, 0);
break;
case 'week':
// 7 00:00:00
//
startTime = new Date(now);
startTime.setDate(startTime.getDate() - 7);
const dayOfWeek = now.getDay(); // 0() to 6()
const diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek; //
startTime.setDate(startTime.getDate() + diffToMonday);
startTime.setHours(0, 0, 0, 0);
break;
case 'month':

View File

@ -199,8 +199,10 @@ function generateTimeRange(period: string): { startTime: string; endTime: string
endTimeDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999); // 23:59:59.999
break;
case 'week':
// 7
startTimeDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 6, 0, 0, 0, 0);
//
const dayOfWeek = now.getDay(); // 0() to 6()
const diffToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek; //
startTimeDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + diffToMonday, 0, 0, 0, 0);
// 23:59:59.999
endTimeDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
break;