getDayOfYear.cjs 896 B

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. exports.getDayOfYear = getDayOfYear;
  3. var _index = require("./differenceInCalendarDays.cjs");
  4. var _index2 = require("./startOfYear.cjs");
  5. var _index3 = require("./toDate.cjs");
  6. /**
  7. * The {@link getDayOfYear} function options.
  8. */
  9. /**
  10. * @name getDayOfYear
  11. * @category Day Helpers
  12. * @summary Get the day of the year of the given date.
  13. *
  14. * @description
  15. * Get the day of the year of the given date.
  16. *
  17. * @param date - The given date
  18. * @param options - The options
  19. *
  20. * @returns The day of year
  21. *
  22. * @example
  23. * // Which day of the year is 2 July 2014?
  24. * const result = getDayOfYear(new Date(2014, 6, 2))
  25. * //=> 183
  26. */
  27. function getDayOfYear(date, options) {
  28. const _date = (0, _index3.toDate)(date, options?.in);
  29. const diff = (0, _index.differenceInCalendarDays)(
  30. _date,
  31. (0, _index2.startOfYear)(_date),
  32. );
  33. const dayOfYear = diff + 1;
  34. return dayOfYear;
  35. }