formatRFC3339.d.ts 1.4 KB

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