( date: Date, format?: 'date' | 'time' | 'date-time' )
| 58 | * convertDateToString(new Date('2023-11-09T14:22:54.131Z')); |
| 59 | */ |
| 60 | export const convertDateToString = ( |
| 61 | date: Date, |
| 62 | format?: 'date' | 'time' | 'date-time' |
| 63 | ): string => { |
| 64 | //e.g. '2023-11-09T14:22:54.131Z' |
| 65 | const dateString = date.toISOString(); |
| 66 | if (format === 'date-time') { |
| 67 | return dateString; |
| 68 | } else if (format === 'date') { |
| 69 | // e.g. '2023-11-09' |
| 70 | return dateString.split('T')[0]; |
| 71 | } else if (format === 'time') { |
| 72 | //e.g. '14:22:54' |
| 73 | return dateString.split('T')[1].split('.')[0]; |
| 74 | } |
| 75 | return dateString; |
| 76 | }; |
| 77 | |
| 78 | /** |
| 79 | * Escape the given string such that it can be used as a class name, |
no outgoing calls
no test coverage detected
searching dependent graphs…