File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
application/CohortManager/src/Web/app/lib Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -15,10 +15,21 @@ export const formatDate = (dateString: string): string => {
1515} ;
1616
1717export 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 = {
You can’t perform that action at this time.
0 commit comments