(date: Date, format?: string, locale?: string, isUTC?: boolean, offset = 0)
| 11 | import { isDateValid } from './utils/type-checks'; |
| 12 | |
| 13 | export function formatDate(date: Date, format?: string, locale?: string, isUTC?: boolean, offset = 0): string { |
| 14 | const _locale = getLocale(locale || 'en'); |
| 15 | if (!_locale) { |
| 16 | throw new Error( |
| 17 | `Locale "${locale}" is not defined, please add it with "defineLocale(...)"` |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 | const _format = format || (isUTC ? 'YYYY-MM-DDTHH:mm:ss[Z]' : 'YYYY-MM-DDTHH:mm:ssZ'); |
| 22 | |
| 23 | const output = formatMoment(date, _format, _locale, isUTC, offset); |
| 24 | |
| 25 | if (!output) { |
| 26 | return output; |
| 27 | } |
| 28 | |
| 29 | return _locale.postformat(output); |
| 30 | } |
| 31 | |
| 32 | // format date using native date object |
| 33 | export function formatMoment(date: Date, _format: string, locale: Locale, isUTC?: boolean, offset = 0): string { |
no test coverage detected