UNPKG

1.84 kBTypeScriptView Raw
1import type { ISOFormatOptions } from "./types.js";
2/**
3 * The {@link formatISO} function options.
4 */
5export interface FormatISOOptions extends ISOFormatOptions {}
6/**
7 * @name formatISO
8 * @category Common Helpers
9 * @summary Format the date according to the ISO 8601 standard (https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003169814.htm).
10 *
11 * @description
12 * Return the formatted date string in ISO 8601 format. Options may be passed to control the parts and notations of the date.
13 *
14 * @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).
15 *
16 * @param date - The original date
17 * @param options - An object with options.
18 *
19 * @returns The formatted date string (in loca.l time zone)
20 *
21 * @throws `date` must not be Invalid Date
22 *
23 * @example
24 * // Represent 18 September 2019 in ISO 8601 format (local time zone is UTC):
25 * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52))
26 * //=> '2019-09-18T19:00:52Z'
27 *
28 * @example
29 * // Represent 18 September 2019 in ISO 8601, short format (local time zone is UTC):
30 * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { format: 'basic' })
31 * //=> '20190918T190052'
32 *
33 * @example
34 * // Represent 18 September 2019 in ISO 8601 format, date only:
35 * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { representation: 'date' })
36 * //=> '2019-09-18'
37 *
38 * @example
39 * // Represent 18 September 2019 in ISO 8601 format, time only (local time zone is UTC):
40 * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { representation: 'time' })
41 * //=> '19:00:52Z'
42 */
43export declare function formatISO<DateType extends Date>(
44 date: DateType | number | string,
45 options?: FormatISOOptions,
46): string;