fix(attendance): 默认周范围改为中国日期周一起点

generateFromSchedules / getCalendar 原来用本地周一零点转 UTC 日期,
在上海时区会得到前一天的日期,导致默认范围变成周日~周日(8 天)。
改为 dayjs().utcOffset(8) 按中国日期计算,与 getTodayDateOnly 语义一致。

新增测试锁定:默认周 = 本周一~本周日,周日晚上仍归本周,显式传参原样透传。
This commit is contained in:
2026-08-08 17:56:00 +08:00
parent 8936453e84
commit 782b43ef0a
4 changed files with 121 additions and 19 deletions

View File

@@ -136,19 +136,14 @@ export class AttendanceGenerationService {
): Promise<{ count: number; records: AttendanceRecord[] }> {
const { classId, startDate, endDate } = dto;
// Default to current week (MondaySunday)
const now = new Date();
const dayOfWeek = now.getDay();
const mondayOffset = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
const monday = new Date(now);
monday.setDate(now.getDate() + mondayOffset);
monday.setHours(0, 0, 0, 0);
const sunday = new Date(monday);
sunday.setDate(monday.getDate() + 6);
sunday.setHours(23, 59, 59, 999);
// Default to current week (MondaySunday), China calendar
const now = dayjs().utcOffset(8);
const day = now.day();
const monday = now.subtract(day === 0 ? 6 : day - 1, 'day').startOf('day');
const sunday = monday.add(6, 'day').endOf('day');
const dateFrom = startDate ?? dayjs(monday).utc().format('YYYY-MM-DD');
const dateTo = endDate ?? dayjs(sunday).utc().format('YYYY-MM-DD');
const dateFrom = startDate ?? monday.format('YYYY-MM-DD');
const dateTo = endDate ?? sunday.format('YYYY-MM-DD');
return this.generateAttendanceFromSchedules({
classId,