refactor(server): 日期/月份格式化统一改用 dayjs
- 替换散落的 toISOString().slice(0,10) / split('T')[0] / replace('T',' ')(UTC 语义用 dayjs(...).utc() 保持完全一致)
- Asia/Shanghai 固定时区日期(Intl.DateTimeFormat en-CA)改用 dayjs().utcOffset(8)
- 月份边界 first/last、daysInMonth、nextMonth、shiftDate/addDays 等改 dayjs 简洁实现
- 涉及 attendance/classes/classrooms/room/dashboard/bills/expenses/occupancies/sync/ai-chat/rental 等 28 个文件
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import dayjs from '../common/dayjs';
|
||||
const DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
||||
const ISO_DATE_PREFIX_PATTERN = /^(\d{4}-\d{2}-\d{2})T/;
|
||||
|
||||
@@ -8,7 +9,7 @@ export function normalizeDateOnly(value?: string | null): string | null | undefi
|
||||
const isoPrefix = ISO_DATE_PREFIX_PATTERN.exec(value)?.[1];
|
||||
if (isoPrefix) {
|
||||
const date = new Date(value);
|
||||
if (!Number.isNaN(date.getTime())) return date.toISOString().slice(0, 10);
|
||||
if (!Number.isNaN(date.getTime())) return dayjs(date).utc().format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
throw new Error(`无效日期格式: ${value}`);
|
||||
|
||||
Reference in New Issue
Block a user