File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
packages/@core/base/shared/src/utils Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,19 @@ dayjs.extend(timezone);
77
88type FormatDate = Date | dayjs . Dayjs | number | string ;
99
10- export function formatDate ( time : FormatDate , format = 'YYYY-MM-DD' ) {
10+ type Format =
11+ | 'HH'
12+ | 'HH:mm'
13+ | 'HH:mm:ss'
14+ | 'YYYY'
15+ | 'YYYY-MM'
16+ | 'YYYY-MM-DD'
17+ | 'YYYY-MM-DD HH'
18+ | 'YYYY-MM-DD HH:mm'
19+ | 'YYYY-MM-DD HH:mm:ss'
20+ | ( string & { } ) ;
21+
22+ export function formatDate ( time ?: FormatDate , format : Format = 'YYYY-MM-DD' ) {
1123 try {
1224 const date = dayjs . isDayjs ( time ) ? time : dayjs ( time ) ;
1325 if ( ! date . isValid ( ) ) {
@@ -16,11 +28,11 @@ export function formatDate(time: FormatDate, format = 'YYYY-MM-DD') {
1628 return date . tz ( ) . format ( format ) ;
1729 } catch ( error ) {
1830 console . error ( `Error formatting date: ${ error } ` ) ;
19- return String ( time ) ;
31+ return String ( time ?? '' ) ;
2032 }
2133}
2234
23- export function formatDateTime ( time : FormatDate ) {
35+ export function formatDateTime ( time ? : FormatDate ) {
2436 return formatDate ( time , 'YYYY-MM-DD HH:mm:ss' ) ;
2537}
2638
You can’t perform that action at this time.
0 commit comments