UNPKG

1.27 kBTypeScriptView Raw
1import type { ContextOptions, DateArg } from "./types.js";
2/**
3 * The {@link formatRFC3339} function options.
4 */
5export interface FormatRFC3339Options extends ContextOptions<Date> {
6 /** The number of digits after the decimal point after seconds, defaults to 0 */
7 fractionDigits?: 0 | 1 | 2 | 3;
8}
9/**
10 * @name formatRFC3339
11 * @category Common Helpers
12 * @summary Format the date according to the RFC 3339 standard (https://tools.ietf.org/html/rfc3339#section-5.6).
13 *
14 * @description
15 * Return the formatted date string in RFC 3339 format. Options may be passed to control the parts and notations of the date.
16 *
17 * @param date - The original date
18 * @param options - An object with options.
19 *
20 * @returns The formatted date string
21 *
22 * @throws `date` must not be Invalid Date
23 *
24 * @example
25 * // Represent 18 September 2019 in RFC 3339 format:
26 * formatRFC3339(new Date(2019, 8, 18, 19, 0, 52))
27 * //=> '2019-09-18T19:00:52Z'
28 *
29 * @example
30 * // Represent 18 September 2019 in RFC 3339 format, 3 digits of second fraction
31 * formatRFC3339(new Date(2019, 8, 18, 19, 0, 52, 234), {
32 * fractionDigits: 3
33 * })
34 * //=> '2019-09-18T19:00:52.234Z'
35 */
36export declare function formatRFC3339(
37 date: DateArg<Date> & {},
38 options?: FormatRFC3339Options,
39): string;