From e17cc8ea3478dfc2aa173498df60b6946852eb74 Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Sun, 16 Mar 2025 04:01:19 +0530 Subject: [PATCH] (fix:date) handle iso 8601 date --- frontend/src/utils/dateTimeUtils.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/frontend/src/utils/dateTimeUtils.ts b/frontend/src/utils/dateTimeUtils.ts index 7f89007c..caddf961 100644 --- a/frontend/src/utils/dateTimeUtils.ts +++ b/frontend/src/utils/dateTimeUtils.ts @@ -1,19 +1,39 @@ export function formatDate(dateString: string): string { - if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dateString)) { + if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(dateString)) { + // ISO 8601 format const dateTime = new Date(dateString); - return dateTime.toLocaleTimeString([], { + return dateTime.toLocaleDateString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', + hour: '2-digit', + minute: '2-digit', + }); + } else if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dateString)) { + const dateTime = new Date(dateString); + return dateTime.toLocaleDateString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', hour: '2-digit', minute: '2-digit', }); } else if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/.test(dateString)) { const dateTime = new Date(dateString); - return dateTime.toLocaleTimeString([], { + return dateTime.toLocaleDateString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', hour: '2-digit', minute: '2-digit', }); } else if (/^\d{4}-\d{2}-\d{2}$/.test(dateString)) { const date = new Date(dateString); - return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }); + return date.toLocaleDateString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', + }); } else { return dateString; }