|
| 1 | +/** |
| 2 | + * Settings for the formatDate and parseDate functions. |
| 3 | + */ |
1 | 4 | export interface DateFormatOptions { |
| 5 | + /** |
| 6 | + * Defines the skeleton format used to get the pattern from the locale calendar [`availableFormats`](http://www.unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems). |
| 7 | + */ |
2 | 8 | skeleton?: string; |
3 | | - date?: string; |
4 | | - time?: string; |
5 | | - datetime?: string; |
6 | | - era?: string; |
7 | | - year?: string; |
8 | | - month?: string; |
9 | | - day?: string; |
10 | | - weekday?: string; |
11 | | - hour?: string; |
| 9 | + |
| 10 | + /** |
| 11 | + * Specifies which of the locale `dateFormats` should be used to format the value. |
| 12 | + */ |
| 13 | + date?: 'short' | 'medium' | 'long' | 'full'; |
| 14 | + |
| 15 | + /** |
| 16 | + * Specifies which of the locale `timeFormats` should be used to format the value. |
| 17 | + */ |
| 18 | + time?: 'short' | 'medium' | 'long' | 'full'; |
| 19 | + |
| 20 | + /** |
| 21 | + * Specifies which of the locale `dateTimeFormats` should be used to format the value. |
| 22 | + */ |
| 23 | + datetime?: 'short' | 'medium' | 'long' | 'full'; |
| 24 | + |
| 25 | + /** |
| 26 | + * Specifies how should the date era be formatted. |
| 27 | + */ |
| 28 | + era?: 'narrow' | 'short' | 'long'; |
| 29 | + |
| 30 | + /** |
| 31 | + * Specifies how the date year should be formatted. |
| 32 | + */ |
| 33 | + year?: 'numeric' | '2-digit'; |
| 34 | + |
| 35 | + /** |
| 36 | + * Specifies how the date month should be formatted. |
| 37 | + */ |
| 38 | + month?: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long'; |
| 39 | + |
| 40 | + /** |
| 41 | + * Specifies how the day of the month should be formatted. |
| 42 | + */ |
| 43 | + day?: 'numeric' | '2-digit'; |
| 44 | + |
| 45 | + /** |
| 46 | + * Specifies how the day of the week should be formatted. |
| 47 | + */ |
| 48 | + weekday?: 'narrow' | 'short' | 'long'; |
| 49 | + |
| 50 | + /** |
| 51 | + * Specifies how the hours should be formatted. |
| 52 | + */ |
| 53 | + hour?: 'numeric' | '2-digit'; |
| 54 | + |
| 55 | + /** |
| 56 | + * Specifies if a 12-hour time set should be used for the formatting. |
| 57 | + */ |
12 | 58 | hour12?: boolean; |
13 | | - minute?: string; |
14 | | - second?: string; |
15 | | - timeZoneName?: string; |
| 59 | + |
| 60 | + /** |
| 61 | + * Specifies how the minutes should be formatted. |
| 62 | + */ |
| 63 | + minute?: 'numeric' | '2-digit'; |
| 64 | + |
| 65 | + /** |
| 66 | + * Specifies how the seconds should be formatted. |
| 67 | + */ |
| 68 | + second?: 'numeric' | '2-digit'; |
| 69 | + |
| 70 | + /** |
| 71 | + * Specifies how the timezone should be formatted. |
| 72 | + */ |
| 73 | + timeZoneName?: 'short' | 'long'; |
16 | 74 | } |
17 | 75 |
|
18 | | -export function formatDate(value: Date, format: String|DateFormatOptions, locale?: string): string; |
| 76 | +/** |
| 77 | + * Converts a `Date` object to a string based on the specified format and locale. |
| 78 | + * |
| 79 | + * @param value Defines the date to be formatted. |
| 80 | + * @param format Defines a string representing a predefined or custom date format, or a configuration object. |
| 81 | + * @param locale The optional locale id. If not specified, the `"en"` locale id is used. |
| 82 | + * @returns The formatted date. |
| 83 | + */ |
| 84 | +export function formatDate(value: Date, format: string|DateFormatOptions, locale?: string): string; |
19 | 85 |
|
20 | | -export function parseDate(value: string, format?: String|DateFormatOptions|Array<String>|Array<DateFormatOptions>, locale?: string): Date; |
| 86 | +/** |
| 87 | + * Converts a string to a `Date` object based on the specified format and locale. |
| 88 | + * |
| 89 | + * @param value Defines the string to be parsed. |
| 90 | + * @param format Defines a string representing a predefined or custom date format, a configuration object, or an array of formats that should be used to parse the value. |
| 91 | + * @param locale The optional locale id. If not specified, the `"en"` locale id is used. |
| 92 | + * @returns The parsed date. |
| 93 | + */ |
| 94 | +export function parseDate(value: string, format?: string | DateFormatOptions | string[] | DateFormatOptions[], locale?: string): Date; |
21 | 95 |
|
22 | | -export function dateFormatString(value: Date, format: String|DateFormatOptions, locale?: string): string; |
| 96 | +/** |
| 97 | + * Returns the full format based on the Date object and the specified format. If no format is provided, the default short date format is used. |
| 98 | + * |
| 99 | + * @param value The date to format. |
| 100 | + * @param format The format string or options. |
| 101 | + * @param locale The optional locale id. If not specified, the `"en"` locale id is used. |
| 102 | + * @returns The full date format. |
| 103 | + */ |
| 104 | +export function dateFormatString(value: Date, format: string|DateFormatOptions, locale?: string): string; |
0 commit comments