index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = lastDayOfQuarter;
  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 lastDayOfQuarter
  11. * @category Quarter Helpers
  12. * @summary Return the last day of a year quarter for the given date.
  13. *
  14. * @description
  15. * Return the last day 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. * @param {Object} [options] - an object with options.
  24. * @param {0|1|2} [options.additionalDigits=2] - passed to `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
  25. * @returns {Date} the last day of a quarter
  26. * @throws {TypeError} 1 argument required
  27. * @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2
  28. *
  29. * @example
  30. * // The last day of a quarter for 2 September 2014 11:55:00:
  31. * var result = lastDayOfQuarter(new Date(2014, 8, 2, 11, 55, 0))
  32. * //=> Tue Sep 30 2014 00:00:00
  33. */
  34. function lastDayOfQuarter(dirtyDate) {
  35. (0, _index2.default)(1, arguments);
  36. var date = (0, _index.default)(dirtyDate);
  37. var currentMonth = date.getMonth();
  38. var month = currentMonth - currentMonth % 3 + 3;
  39. date.setMonth(month, 0);
  40. date.setHours(0, 0, 0, 0);
  41. return date;
  42. }
  43. module.exports = exports.default;