Skip to content

Commit 63bd8c2

Browse files
fix: handle date format (#1637)
* fix: handle date format * fix: handle date format
1 parent 1dc2529 commit 63bd8c2

File tree

1 file changed

+15
-4
lines changed
  • application/CohortManager/src/Web/app/lib

1 file changed

+15
-4
lines changed

application/CohortManager/src/Web/app/lib/utils.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@ export const formatDate = (dateString: string): string => {
1515
};
1616

1717
export const formatCompactDate = (dateString: string): string => {
18-
if (!dateString || dateString.length < 8) return "";
19-
const year = dateString.slice(0, 4);
20-
const month = dateString.slice(4, 6);
21-
const day = dateString.slice(6, 8);
18+
if (!dateString) return "";
19+
20+
let year: string, month: string, day: string;
21+
22+
if (dateString.includes('-') || dateString.includes('/')) {
23+
const parts = dateString.split(/[-/]/);
24+
if (parts.length !== 3) return "";
25+
[year, month, day] = parts;
26+
} else {
27+
if (dateString.length < 8) return "";
28+
year = dateString.slice(0, 4);
29+
month = dateString.slice(4, 6);
30+
day = dateString.slice(6, 8);
31+
}
32+
2233
const date = new Date(`${year}-${month}-${day}`);
2334
if (isNaN(date.getTime())) return "";
2435
const options: Intl.DateTimeFormatOptions = {

0 commit comments

Comments
 (0)