index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = setDayOfYear;
  6. var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
  7. var _index2 = _interopRequireDefault(require("../toDate/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 setDayOfYear
  12. * @category Day Helpers
  13. * @summary Set the day of the year to the given date.
  14. *
  15. * @description
  16. * Set the day of the year to the given date.
  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 date to be changed
  23. * @param {Number} dayOfYear - the day of the year of the new date
  24. * @returns {Date} the new date with the day of the year set
  25. * @throws {TypeError} 2 arguments required
  26. *
  27. * @example
  28. * // Set the 2nd day of the year to 2 July 2014:
  29. * var result = setDayOfYear(new Date(2014, 6, 2), 2)
  30. * //=> Thu Jan 02 2014 00:00:00
  31. */
  32. function setDayOfYear(dirtyDate, dirtyDayOfYear) {
  33. (0, _index3.default)(2, arguments);
  34. var date = (0, _index2.default)(dirtyDate);
  35. var dayOfYear = (0, _index.default)(dirtyDayOfYear);
  36. date.setMonth(0);
  37. date.setDate(dayOfYear);
  38. return date;
  39. }
  40. module.exports = exports.default;