formatDistanceToNowStrict.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. exports.formatDistanceToNowStrict = formatDistanceToNowStrict;
  3. var _index = require("./formatDistanceStrict.js");
  4. var _index2 = require("./constructNow.js");
  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. * @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).
  29. *
  30. * @param date - The given date
  31. * @param options - An object with options.
  32. *
  33. * @returns The distance in words
  34. *
  35. * @throws `date` must not be Invalid Date
  36. * @throws `options.locale` must contain `formatDistance` property
  37. *
  38. * @example
  39. * // If today is 1 January 2015, what is the distance to 2 July 2014?
  40. * const result = formatDistanceToNowStrict(
  41. * new Date(2014, 6, 2)
  42. * )
  43. * //=> '6 months'
  44. *
  45. * @example
  46. * // If now is 1 January 2015 00:00:00,
  47. * // what is the distance to 1 January 2015 00:00:15, including seconds?
  48. * const result = formatDistanceToNowStrict(
  49. * new Date(2015, 0, 1, 0, 0, 15)
  50. * )
  51. * //=> '15 seconds'
  52. *
  53. * @example
  54. * // If today is 1 January 2015,
  55. * // what is the distance to 1 January 2016, with a suffix?
  56. * const result = formatDistanceToNowStrict(
  57. * new Date(2016, 0, 1),
  58. * {addSuffix: true}
  59. * )
  60. * //=> 'in 1 year'
  61. *
  62. * @example
  63. * // If today is 28 January 2015,
  64. * // what is the distance to 1 January 2015, in months, rounded up??
  65. * const result = formatDistanceToNowStrict(new Date(2015, 0, 1), {
  66. * unit: 'month',
  67. * roundingMethod: 'ceil'
  68. * })
  69. * //=> '1 month'
  70. *
  71. * @example
  72. * // If today is 1 January 2015,
  73. * // what is the distance to 1 January 2016 in Esperanto?
  74. * const eoLocale = require('date-fns/locale/eo')
  75. * const result = formatDistanceToNowStrict(
  76. * new Date(2016, 0, 1),
  77. * {locale: eoLocale}
  78. * )
  79. * //=> '1 jaro'
  80. */
  81. function formatDistanceToNowStrict(date, options) {
  82. return (0, _index.formatDistanceStrict)(
  83. date,
  84. (0, _index2.constructNow)(date),
  85. options,
  86. );
  87. }