getDaysInYear.cjs 812 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. exports.getDaysInYear = getDaysInYear;
  3. var _index = require("./isLeapYear.cjs");
  4. var _index2 = require("./toDate.cjs");
  5. /**
  6. * The {@link getDaysInYear} function options.
  7. */
  8. /**
  9. * @name getDaysInYear
  10. * @category Year Helpers
  11. * @summary Get the number of days in a year of the given date.
  12. *
  13. * @description
  14. * Get the number of days in a year of the given date.
  15. *
  16. * @param date - The given date
  17. * @param options - An object with options
  18. *
  19. * @returns The number of days in a year
  20. *
  21. * @example
  22. * // How many days are in 2012?
  23. * const result = getDaysInYear(new Date(2012, 0, 1))
  24. * //=> 366
  25. */
  26. function getDaysInYear(date, options) {
  27. const _date = (0, _index2.toDate)(date, options?.in);
  28. if (Number.isNaN(+_date)) return NaN;
  29. return (0, _index.isLeapYear)(_date) ? 366 : 365;
  30. }