index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = formatDistanceToNowStrict;
  6. var _index = _interopRequireDefault(require("../formatDistanceStrict/index.js"));
  7. var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  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|Number} date - the given date
  30. * @param {Object} [options] - an object with options.
  31. * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first
  32. * @param {'second'|'minute'|'hour'|'day'|'month'|'year'} [options.unit] - if specified, will force a unit
  33. * @param {'floor'|'ceil'|'round'} [options.roundingMethod='round'] - which way to round partial units
  34. * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
  35. * @returns {String} the distance in words
  36. * @throws {TypeError} 1 argument required
  37. * @throws {RangeError} `date` must not be Invalid Date
  38. * @throws {RangeError} `options.locale` must contain `formatDistance` property
  39. *
  40. * @example
  41. * // If today is 1 January 2015, what is the distance to 2 July 2014?
  42. * var result = formatDistanceToNowStrict(
  43. * new Date(2014, 6, 2)
  44. * )
  45. * //=> '6 months'
  46. *
  47. * @example
  48. * // If now is 1 January 2015 00:00:00,
  49. * // what is the distance to 1 January 2015 00:00:15, including seconds?
  50. * var result = formatDistanceToNowStrict(
  51. * new Date(2015, 0, 1, 0, 0, 15)
  52. * )
  53. * //=> '20 seconds'
  54. *
  55. * @example
  56. * // If today is 1 January 2015,
  57. * // what is the distance to 1 January 2016, with a suffix?
  58. * var result = formatDistanceToNowStrict(
  59. * new Date(2016, 0, 1),
  60. * {addSuffix: true}
  61. * )
  62. * //=> 'in 1 year'
  63. *
  64. * @example
  65. * // If today is 28 January 2015,
  66. * // what is the distance to 1 January 2015, in months, rounded up??
  67. * var result = formatDistanceToNowStrict(new Date(2015, 0, 1), {
  68. * unit: 'month',
  69. * roundingMethod: 'ceil'
  70. * })
  71. * //=> '1 month'
  72. *
  73. * @example
  74. * // If today is 1 January 2015,
  75. * // what is the distance to 1 August 2016 in Esperanto?
  76. * var eoLocale = require('date-fns/locale/eo')
  77. * var result = formatDistanceToNowStrict(
  78. * new Date(2016, 7, 1),
  79. * {locale: eoLocale}
  80. * )
  81. * //=> '1 jaro'
  82. */
  83. function formatDistanceToNowStrict(dirtyDate, dirtyOptions) {
  84. (0, _index2.default)(1, arguments);
  85. return (0, _index.default)(dirtyDate, Date.now(), dirtyOptions);
  86. }
  87. module.exports = exports.default;