formatDistanceToNowStrict.cjs 2.5 KB

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