feat: 添加日期格式化函数的空值处理

- 当传入的时间参数为 undefined、null 或空字符串时,直接返回空字符串而不是继续执行格式化逻辑,避免无效的时间值导致程序错误。
This commit is contained in:
boisduval
2026-04-23 17:25:10 +08:00
parent 3a83fb0c3e
commit c7fd6ffb0e

View File

@@ -20,6 +20,9 @@ type Format =
| (string & {});
export function formatDate(time?: FormatDate, format: Format = 'YYYY-MM-DD') {
if (time === undefined || time === null || time === '') {
return '';
}
try {
const date = dayjs.isDayjs(time) ? time : dayjs(time);
if (!date.isValid()) {