index.js 1.1 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 = lastDayOfYear;
  7. var _index = _interopRequireDefault(require("../toDate/index.js"));
  8. var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  9. /**
  10. * @name lastDayOfYear
  11. * @category Year Helpers
  12. * @summary Return the last day of a year for the given date.
  13. *
  14. * @description
  15. * Return the last day of a year for the given date.
  16. * The result will be in the local timezone.
  17. *
  18. * @param {Date|Number} date - the original date
  19. * @returns {Date} the last day of a year
  20. * @throws {TypeError} 1 argument required
  21. *
  22. * @example
  23. * // The last day of a year for 2 September 2014 11:55:00:
  24. * const result = lastDayOfYear(new Date(2014, 8, 2, 11, 55, 00))
  25. * //=> Wed Dec 31 2014 00:00:00
  26. */
  27. function lastDayOfYear(dirtyDate) {
  28. (0, _index2.default)(1, arguments);
  29. var date = (0, _index.default)(dirtyDate);
  30. var year = date.getFullYear();
  31. date.setFullYear(year + 1, 0, 0);
  32. date.setHours(0, 0, 0, 0);
  33. return date;
  34. }
  35. module.exports = exports.default;