refactor(server): 日期工具统一迁入 dayjs(utc 插件),移除手写 Intl/padStart 重复实现
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
ScheduleType,
|
||||
} from '../entities';
|
||||
import { toMinutes, isClassStudentActiveOnDate } from './attendance-time';
|
||||
import dayjs from '../common/dayjs';
|
||||
import type { BatchCreateAttendanceDto, GenerateAttendanceFromSchedulesDto, GenerateFromSchedulesDto, SaveAttendancePeriodConfigsDto } from './dto/attendance.dto';
|
||||
|
||||
@Injectable()
|
||||
@@ -162,23 +163,15 @@ export class AttendanceGenerationService {
|
||||
}
|
||||
|
||||
private getCourseClock(date: Date): { date: string; minutes: number } {
|
||||
const parts = Object.fromEntries(
|
||||
new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||
hour: '2-digit', minute: '2-digit', hourCycle: 'h23',
|
||||
}).formatToParts(date).filter((part) => part.type !== 'literal').map((part) => [part.type, part.value]),
|
||||
);
|
||||
const c = dayjs.utc(date).add(8, 'hour');
|
||||
return {
|
||||
date: `${parts.year}-${parts.month}-${parts.day}`,
|
||||
minutes: Number(parts.hour) * 60 + Number(parts.minute),
|
||||
date: c.format('YYYY-MM-DD'),
|
||||
minutes: c.hour() * 60 + c.minute(),
|
||||
};
|
||||
}
|
||||
|
||||
private shiftDate(date: string, days: number): string {
|
||||
const shifted = new Date(`${date}T00:00:00.000Z`);
|
||||
shifted.setUTCDate(shifted.getUTCDate() + days);
|
||||
return shifted.toISOString().slice(0, 10);
|
||||
return dayjs.utc(`${date}T00:00:00.000Z`).add(days, 'day').format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
private async ensureAttendancePeriodConfigs() {
|
||||
|
||||
Reference in New Issue
Block a user