forked from wangziqi/gongxue-base
feat: 考勤模块重构与钉钉考勤同步
This commit is contained in:
43
apps/server/src/attendance/attendance-time.ts
Normal file
43
apps/server/src/attendance/attendance-time.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
export function toMinutes(time: string): number {
|
||||
const [hour, minute] = time.split(':').map(Number);
|
||||
return hour * 60 + minute;
|
||||
}
|
||||
|
||||
export function getCourseClock(date: Date): { date: string; minutes: number } {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return {
|
||||
date: `${year}-${month}-${day}`,
|
||||
minutes: date.getHours() * 60 + date.getMinutes(),
|
||||
};
|
||||
}
|
||||
|
||||
export function shiftDate(date: string, days: number): string {
|
||||
const d = new Date(`${date}T00:00:00.000Z`);
|
||||
d.setUTCDate(d.getUTCDate() + days);
|
||||
return d.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
export function mapLessonScheduleTimeToSession(startTime: string): string {
|
||||
const hour = parseInt(startTime.slice(0, 2), 10);
|
||||
if (hour < 8) return 'morning_reading';
|
||||
if (hour < 12) return 'morning';
|
||||
if (hour < 17) return 'afternoon';
|
||||
if (hour < 20) return 'evening_study';
|
||||
return 'night_check';
|
||||
}
|
||||
|
||||
export function isClassStudentActiveOnDate(
|
||||
classStudent: Pick<
|
||||
import('../entities/class-student.entity').ClassStudent,
|
||||
'joinDate' | 'leaveDate' | 'status'
|
||||
>,
|
||||
lessonDate: string,
|
||||
): boolean {
|
||||
const status = classStudent.status ?? 'active';
|
||||
if (!['active', 'left'].includes(status)) return false;
|
||||
if (classStudent.joinDate && classStudent.joinDate > lessonDate) return false;
|
||||
if (classStudent.leaveDate && classStudent.leaveDate < lessonDate) return false;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user