UNPKG

1.77 kBTypeScriptView Raw
1import type { ContextOptions } from "./types.js";
2/**
3 * The {@link parseISO} function options.
4 */
5export interface ParseISOOptions<DateType extends Date = Date>
6 extends ContextOptions<DateType> {
7 /** The additional number of digits in the extended year format */
8 additionalDigits?: 0 | 1 | 2;
9}
10/**
11 * @name parseISO
12 * @category Common Helpers
13 * @summary Parse ISO string
14 *
15 * @description
16 * Parse the given string in ISO 8601 format and return an instance of Date.
17 *
18 * Function accepts complete ISO 8601 formats as well as partial implementations.
19 * ISO 8601: http://en.wikipedia.org/wiki/ISO_8601
20 *
21 * If the argument isn't a string, the function cannot parse the string or
22 * the values are invalid, it returns Invalid Date.
23 *
24 * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
25 * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
26 *
27 * @param argument - The value to convert
28 * @param options - An object with options
29 *
30 * @returns The parsed date in the local time zone
31 *
32 * @example
33 * // Convert string '2014-02-11T11:30:30' to date:
34 * const result = parseISO('2014-02-11T11:30:30')
35 * //=> Tue Feb 11 2014 11:30:30
36 *
37 * @example
38 * // Convert string '+02014101' to date,
39 * // if the additional number of digits in the extended year format is 1:
40 * const result = parseISO('+02014101', { additionalDigits: 1 })
41 * //=> Fri Apr 11 2014 00:00:00
42 */
43export declare function parseISO<
44 DateType extends Date,
45 ResultDate extends Date = DateType,
46>(argument: string, options?: ParseISOOptions<ResultDate>): ResultDate;