mirror of
https://github.com/imdap/ruoyi-plus-vben5.git
synced 2026-05-09 03:51:25 +08:00
feat: 添加日期格式化函数的空值处理
- 当传入的时间参数为 undefined、null 或空字符串时,直接返回空字符串而不是继续执行格式化逻辑,避免无效的时间值导致程序错误。
This commit is contained in:
@@ -20,6 +20,9 @@ type Format =
|
|||||||
| (string & {});
|
| (string & {});
|
||||||
|
|
||||||
export function formatDate(time?: FormatDate, format: Format = 'YYYY-MM-DD') {
|
export function formatDate(time?: FormatDate, format: Format = 'YYYY-MM-DD') {
|
||||||
|
if (time === undefined || time === null || time === '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const date = dayjs.isDayjs(time) ? time : dayjs(time);
|
const date = dayjs.isDayjs(time) ? time : dayjs(time);
|
||||||
if (!date.isValid()) {
|
if (!date.isValid()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user