vremel
Version:
JavaScript date utility library for Temporal API
111 lines • 6.04 kB
TypeScript
/**
* parse result which can be passed to `Temporal.XX.from` static method.
*/
export interface ParseResult {
era?: string;
eraYear?: number;
year?: number;
month?: number;
monthCode?: string;
day?: number;
hour?: number;
minute?: number;
second?: number;
millisecond?: number;
microsecond?: number;
nanosecond?: number;
}
/**
* Locale data.
* Each property of the locale object corresponds to a format style.
* For example, `locale.month.format.abbreviated` means 'format' form and 'abbreviated' style months.
*/
export interface LocaleDataForParser {
era?: {
abbreviated?: Record<string, string> | undefined;
wide?: Record<string, string> | undefined;
narrow?: Record<string, string> | undefined;
} | undefined;
month?: {
format?: {
abbreviated?: Record<string, string> | string[] | undefined;
wide?: Record<string, string> | string[] | undefined;
narrow?: Record<string, string> | string[] | undefined;
} | undefined;
standalone?: {
abbreviated?: Record<string, string> | string[] | undefined;
wide?: Record<string, string> | string[] | undefined;
narrow?: Record<string, string> | string[] | undefined;
} | undefined;
} | undefined;
dayPeriod?: {
abbreviated?: Record<string, string> | undefined;
wide?: Record<string, string> | undefined;
narrow?: Record<string, string> | undefined;
} | undefined;
}
/**
* Return the object parsed from string using the given format string.
*
* ```typescript
* Temporal.PlainDate.from(parse('2/9/2025', 'M/d/yyyy'))
* // 2025-02-09
* ```
*
* Characters between two single quotes (`'`) in the format are escaped.
* Two consecutive single quotes (`''`) in the format always represents one single quote (`'`).
* Letters `A` to `Z` and `a` to `z` are reserved for use as pattern characters, unless they are escaped.
*
* Available field patterns are subset of date field symbols in Unicode CLDR,
* see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table for details.
*
* Basically 3 characters' field (e.g. `MMM`) means 'abbreviated' style,
* 4 characters' field (e.g. `MMMM`) means 'wide' style,
* 5 characters's field (e.g. `MMMMM`) means 'narrow' style.
*
* Available patterns:
* | unit | field | result examples |
* | ------------------ | ---------------- | --------------------------------------- |
* | era | G, GG, GGG | AD, BC |
* | | GGGG | Anno Domini, Before Christ |
* | | GGGGG | A, B |
* | calendar year | y | 2, 20, 201, 2000, 20020 |
* | | yyy | 002, 020, 201, 2000, 20020 |
* | | yyyy | 0002, 0020, 0201, 2000, 20020 |
* | | yyyyy, yyyyyy... | (at least `n` digits with zero-padding) |
* | month (format) | M | 1, 12 |
* | | MM | 01, 12 |
* | | MMM | Jan, Feb, ... |
* | | MMMM | January, February, ... |
* | | MMMMM | J, F, ... |
* | month (standalone) | L | 1, 12 |
* | | LL | 01, 12 |
* | | LLL | Jan, Feb, ... |
* | | LLLL | January, February, ... |
* | | LLLLL | J, F, ... |
* | day | d | 1, 31 |
* | | dd | 01, 31 |
* | AM, PM | a, aa, aaa | AM, PM |
* | | aaaa | a.m., p.m. |
* | | aaaaa | a, p |
* | hour (1-12) | h | 12, 1, 11 |
* | | hh | 12, 01, 11 |
* | hour (0-23) | H | 0, 1, 23 |
* | | HH | 00, 01, 23 |
* | hour (0-11) | K | 0, 1, 11 |
* | | KK | 00, 01, 11 |
* | minute | m | 0, 59 |
* | | mm | 00, 59 |
* | second | s | 0, 59 |
* | | ss | 00, 59 |
* | fraction of second | S | 1, 8 |
* | | SS | 10, 83 |
* | | SSS, SSSS... | (`n` digits) |
*
* @param dateTimeString string representing a date
* @param pattern date format pattern string
* @param localeData optional locale data (required when using non-numeric pattern fields)
* @returns parse result which can be passed to `Temporal.XX.from` static method.
*/
export declare function parse(dateTimeString: string, pattern: string, localeData?: LocaleDataForParser): ParseResult;
//# sourceMappingURL=parse.d.ts.map