refactor(server): 日期工具统一迁入 dayjs(utc 插件),移除手写 Intl/padStart 重复实现
This commit is contained in:
@@ -1,22 +1,20 @@
|
||||
import dayjs from '../common/dayjs';
|
||||
|
||||
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');
|
||||
const d = dayjs(date);
|
||||
return {
|
||||
date: `${year}-${month}-${day}`,
|
||||
minutes: date.getHours() * 60 + date.getMinutes(),
|
||||
date: d.format('YYYY-MM-DD'),
|
||||
minutes: d.hour() * 60 + d.minute(),
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
return dayjs.utc(`${date}T00:00:00.000Z`).add(days, 'day').format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
export function mapLessonScheduleTimeToSession(startTime: string): string {
|
||||
|
||||
Reference in New Issue
Block a user