formatDistanceToNowStrict.d.cts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import type { FormatDistanceStrictOptions } from "./formatDistanceStrict.js";
  2. import type { ContextOptions, DateArg } from "./types.js";
  3. /**
  4. * The {@link formatDistanceToNowStrict} function options.
  5. */
  6. export interface FormatDistanceToNowStrictOptions
  7. extends FormatDistanceStrictOptions,
  8. ContextOptions<Date> {}
  9. /**
  10. * @name formatDistanceToNowStrict
  11. * @category Common Helpers
  12. * @summary Return the distance between the given date and now in words.
  13. * @pure false
  14. *
  15. * @description
  16. * Return the distance between the given dates in words, using strict units.
  17. * This is like `formatDistance`, but does not use helpers like 'almost', 'over',
  18. * 'less than' and the like.
  19. *
  20. * | Distance between dates | Result |
  21. * |------------------------|---------------------|
  22. * | 0 ... 59 secs | [0..59] seconds |
  23. * | 1 ... 59 mins | [1..59] minutes |
  24. * | 1 ... 23 hrs | [1..23] hours |
  25. * | 1 ... 29 days | [1..29] days |
  26. * | 1 ... 11 months | [1..11] months |
  27. * | 1 ... N years | [1..N] years |
  28. *
  29. * @param date - The given date
  30. * @param options - An object with options.
  31. *
  32. * @returns The distance in words
  33. *
  34. * @throws `date` must not be Invalid Date
  35. * @throws `options.locale` must contain `formatDistance` property
  36. *
  37. * @example
  38. * // If today is 1 January 2015, what is the distance to 2 July 2014?
  39. * const result = formatDistanceToNowStrict(
  40. * new Date(2014, 6, 2)
  41. * )
  42. * //=> '6 months'
  43. *
  44. * @example
  45. * // If now is 1 January 2015 00:00:00,
  46. * // what is the distance to 1 January 2015 00:00:15, including seconds?
  47. * const result = formatDistanceToNowStrict(
  48. * new Date(2015, 0, 1, 0, 0, 15)
  49. * )
  50. * //=> '15 seconds'
  51. *
  52. * @example
  53. * // If today is 1 January 2015,
  54. * // what is the distance to 1 January 2016, with a suffix?
  55. * const result = formatDistanceToNowStrict(
  56. * new Date(2016, 0, 1),
  57. * {addSuffix: true}
  58. * )
  59. * //=> 'in 1 year'
  60. *
  61. * @example
  62. * // If today is 28 January 2015,
  63. * // what is the distance to 1 January 2015, in months, rounded up??
  64. * const result = formatDistanceToNowStrict(new Date(2015, 0, 1), {
  65. * unit: 'month',
  66. * roundingMethod: 'ceil'
  67. * })
  68. * //=> '1 month'
  69. *
  70. * @example
  71. * // If today is 1 January 2015,
  72. * // what is the distance to 1 January 2016 in Esperanto?
  73. * const eoLocale = require('date-fns/locale/eo')
  74. * const result = formatDistanceToNowStrict(
  75. * new Date(2016, 0, 1),
  76. * {locale: eoLocale}
  77. * )
  78. * //=> '1 jaro'
  79. */
  80. export declare function formatDistanceToNowStrict(
  81. date: DateArg<Date> & {},
  82. options?: FormatDistanceToNowStrictOptions,
  83. ): string;