UNPKG

1.77 kBTypeScriptView Raw
1import type { ISOFormatOptions } from "./types.js";
2/**
3 * The {@link formatISO9075} function options.
4 */
5export interface FormatISO9075Options extends ISOFormatOptions {}
6/**
7 * @name formatISO9075
8 * @category Common Helpers
9 * @summary Format the date according to the ISO 9075 standard (https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_get-format).
10 *
11 * @description
12 * Return the formatted date string in ISO 9075 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
20 *
21 * @throws `date` must not be Invalid Date
22 *
23 * @example
24 * // Represent 18 September 2019 in ISO 9075 format:
25 * const result = formatISO9075(new Date(2019, 8, 18, 19, 0, 52))
26 * //=> '2019-09-18 19:00:52'
27 *
28 * @example
29 * // Represent 18 September 2019 in ISO 9075, short format:
30 * const result = formatISO9075(new Date(2019, 8, 18, 19, 0, 52), { format: 'basic' })
31 * //=> '20190918 190052'
32 *
33 * @example
34 * // Represent 18 September 2019 in ISO 9075 format, date only:
35 * const result = formatISO9075(new Date(2019, 8, 18, 19, 0, 52), { representation: 'date' })
36 * //=> '2019-09-18'
37 *
38 * @example
39 * // Represent 18 September 2019 in ISO 9075 format, time only:
40 * const result = formatISO9075(new Date(2019, 8, 18, 19, 0, 52), { representation: 'time' })
41 * //=> '19:00:52'
42 */
43export declare function formatISO9075<DateType extends Date>(
44 date: DateType | number | string,
45 options?: FormatISO9075Options,
46): string;