Skip to content

Commit

Permalink
chore(web): handle invalid date in time convert (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice authored Jan 24, 2024
1 parent 46593d6 commit c8e8253
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions web/src/beta/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export const convertTime = (time: string | Date | undefined): Date | undefined => {
if (!time) return;
if (time instanceof Date) return time;
if (time instanceof Date) {
return !isNaN(time.getTime()) ? time : undefined;
}
try {
return new Date(time);
const dateTime = new Date(time);
return !isNaN(dateTime.getTime()) ? dateTime : undefined;
} catch {
return undefined;
}
Expand Down

0 comments on commit c8e8253

Please sign in to comment.