index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = endOfQuarter;
  6. var _index = _interopRequireDefault(require("../toDate/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 endOfQuarter
  11. * @category Quarter Helpers
  12. * @summary Return the end of a year quarter for the given date.
  13. *
  14. * @description
  15. * Return the end of a year quarter for the given date.
  16. * The result will be in the local timezone.
  17. *
  18. * ### v2.0.0 breaking changes:
  19. *
  20. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  21. *
  22. * @param {Date|Number} date - the original date
  23. * @returns {Date} the end of a quarter
  24. * @throws {TypeError} 1 argument required
  25. *
  26. * @example
  27. * // The end of a quarter for 2 September 2014 11:55:00:
  28. * const result = endOfQuarter(new Date(2014, 8, 2, 11, 55, 0))
  29. * //=> Tue Sep 30 2014 23:59:59.999
  30. */
  31. function endOfQuarter(dirtyDate) {
  32. (0, _index2.default)(1, arguments);
  33. var date = (0, _index.default)(dirtyDate);
  34. var currentMonth = date.getMonth();
  35. var month = currentMonth - currentMonth % 3 + 3;
  36. date.setMonth(month, 0);
  37. date.setHours(23, 59, 59, 999);
  38. return date;
  39. }
  40. module.exports = exports.default;