index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = lastDayOfDecade;
  7. var _index = _interopRequireDefault(require("../toDate/index.js"));
  8. var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  9. /**
  10. * @name lastDayOfDecade
  11. * @category Decade Helpers
  12. * @summary Return the last day of a decade for the given date.
  13. *
  14. * @description
  15. * Return the last day of a decade for the given date.
  16. *
  17. * @param {Date|Number} date - the original date
  18. * @returns {Date} the last day of a decade
  19. * @throws {TypeError} 1 argument required
  20. *
  21. * @example
  22. * // The last day of a decade for 21 December 2012 21:12:00:
  23. * const result = lastDayOfDecade(new Date(2012, 11, 21, 21, 12, 00))
  24. * //=> Wed Dec 31 2019 00:00:00
  25. */
  26. function lastDayOfDecade(dirtyDate) {
  27. (0, _index2.default)(1, arguments);
  28. var date = (0, _index.default)(dirtyDate);
  29. var year = date.getFullYear();
  30. var decade = 9 + Math.floor(year / 10) * 10;
  31. date.setFullYear(decade + 1, 0, 0);
  32. date.setHours(0, 0, 0, 0);
  33. return date;
  34. }
  35. module.exports = exports.default;