getDateTimeFormatOptions() function
Given a parsed ICU date/time formatter pattern, constructs a corresponding Intl.DateTimeFormat
options structure.
Signature:
export declare function getDateTimeFormatOptions(tokens: DateToken[], onError: (type: DateFormatError['type'], message: string, token: DateToken) => void): Intl.DateTimeFormatOptions;
Parameters
Parameter | Type | Description |
---|---|---|
tokens | DateToken[] | |
onError | (type: DateFormatError[‘type’], message: string, token: DateToken) => void | Called if encountering invalid or unsupported tokens, such as literal strings and day-of-week fields. |
Returns:
Intl.DateTimeFormatOptions
Example
import { getDateTimeFormatOptions, parseDateTokens } from '@messageformat/date-skeleton'
const tokens = parseDateTokens('GyMMMMdd', console.error)
getDateTimeFormatOptions(tokens, console.error)
{
era: 'short',
year: 'numeric',
month: 'long',
day: '2-digit'
}