index.js 945 B

1234567891011121314151617181920212223242526272829
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import toDate from "../toDate/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.js";
  4. /**
  5. * @name setDayOfYear
  6. * @category Day Helpers
  7. * @summary Set the day of the year to the given date.
  8. *
  9. * @description
  10. * Set the day of the year to the given date.
  11. *
  12. * @param {Date|Number} date - the date to be changed
  13. * @param {Number} dayOfYear - the day of the year of the new date
  14. * @returns {Date} the new date with the day of the year set
  15. * @throws {TypeError} 2 arguments required
  16. *
  17. * @example
  18. * // Set the 2nd day of the year to 2 July 2014:
  19. * const result = setDayOfYear(new Date(2014, 6, 2), 2)
  20. * //=> Thu Jan 02 2014 00:00:00
  21. */
  22. export default function setDayOfYear(dirtyDate, dirtyDayOfYear) {
  23. requiredArgs(2, arguments);
  24. var date = toDate(dirtyDate);
  25. var dayOfYear = toInteger(dirtyDayOfYear);
  26. date.setMonth(0);
  27. date.setDate(dayOfYear);
  28. return date;
  29. }