47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import type { ContextOptions } from "./types.js";
|
|
/**
|
|
* The {@link parseISO} function options.
|
|
*/
|
|
export interface ParseISOOptions<DateType extends Date = Date>
|
|
extends ContextOptions<DateType> {
|
|
/** The additional number of digits in the extended year format */
|
|
additionalDigits?: 0 | 1 | 2;
|
|
}
|
|
/**
|
|
* @name parseISO
|
|
* @category Common Helpers
|
|
* @summary Parse ISO string
|
|
*
|
|
* @description
|
|
* Parse the given string in ISO 8601 format and return an instance of Date.
|
|
*
|
|
* Function accepts complete ISO 8601 formats as well as partial implementations.
|
|
* ISO 8601: http://en.wikipedia.org/wiki/ISO_8601
|
|
*
|
|
* If the argument isn't a string, the function cannot parse the string or
|
|
* the values are invalid, it returns Invalid Date.
|
|
*
|
|
* @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).
|
|
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
|
*
|
|
* @param argument - The value to convert
|
|
* @param options - An object with options
|
|
*
|
|
* @returns The parsed date in the local time zone
|
|
*
|
|
* @example
|
|
* // Convert string '2014-02-11T11:30:30' to date:
|
|
* const result = parseISO('2014-02-11T11:30:30')
|
|
* //=> Tue Feb 11 2014 11:30:30
|
|
*
|
|
* @example
|
|
* // Convert string '+02014101' to date,
|
|
* // if the additional number of digits in the extended year format is 1:
|
|
* const result = parseISO('+02014101', { additionalDigits: 1 })
|
|
* //=> Fri Apr 11 2014 00:00:00
|
|
*/
|
|
export declare function parseISO<
|
|
DateType extends Date,
|
|
ResultDate extends Date = DateType,
|
|
>(argument: string, options?: ParseISOOptions<ResultDate>): ResultDate;
|