Skip to content

Commit

Permalink
chore: typo
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Nov 9, 2024
1 parent b3cb7ee commit 348d0ee
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/@core/base/shared/src/utils/date.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import dayjs from 'dayjs';

export function formatDate(time: number | string, format = 'YYYY-MM-DD') {
return dayjs(time).format(format);
try {
const date = dayjs(time);
if (!date.isValid()) {
throw new Error('Invalid date');
}
return date.format(format);
} catch (error) {
console.error(`Error formatting date: ${error}`);
return time;
}
}

export function formatDateTime(time: number | string) {
Expand Down

0 comments on commit 348d0ee

Please sign in to comment.