index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = endOfISOWeekYear;
  6. var _index = _interopRequireDefault(require("../getISOWeekYear/index.js"));
  7. var _index2 = _interopRequireDefault(require("../startOfISOWeek/index.js"));
  8. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * @name endOfISOWeekYear
  12. * @category ISO Week-Numbering Year Helpers
  13. * @summary Return the end of an ISO week-numbering year for the given date.
  14. *
  15. * @description
  16. * Return the end of an ISO week-numbering year,
  17. * which always starts 3 days before the year's first Thursday.
  18. * The result will be in the local timezone.
  19. *
  20. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  21. *
  22. * ### v2.0.0 breaking changes:
  23. *
  24. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  25. *
  26. * - The function was renamed from `endOfISOYear` to `endOfISOWeekYear`.
  27. * "ISO week year" is short for [ISO week-numbering year](https://en.wikipedia.org/wiki/ISO_week_date).
  28. * This change makes the name consistent with
  29. * locale-dependent week-numbering year helpers, e.g., `addWeekYears`.
  30. *
  31. * @param {Date|Number} date - the original date
  32. * @returns {Date} the end of an ISO week-numbering year
  33. * @throws {TypeError} 1 argument required
  34. *
  35. * @example
  36. * // The end of an ISO week-numbering year for 2 July 2005:
  37. * const result = endOfISOWeekYear(new Date(2005, 6, 2))
  38. * //=> Sun Jan 01 2006 23:59:59.999
  39. */
  40. function endOfISOWeekYear(dirtyDate) {
  41. (0, _index3.default)(1, arguments);
  42. var year = (0, _index.default)(dirtyDate);
  43. var fourthOfJanuaryOfNextYear = new Date(0);
  44. fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
  45. fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
  46. var date = (0, _index2.default)(fourthOfJanuaryOfNextYear);
  47. date.setMilliseconds(date.getMilliseconds() - 1);
  48. return date;
  49. }
  50. module.exports = exports.default;