25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 년 전
1234567891011121314151617181920212223242526272829303132333435
  1. import toDate from '../toDate/index.js';
  2. import isLeapYear from '../isLeapYear/index.js';
  3. import requiredArgs from '../_lib/requiredArgs/index.js';
  4. /**
  5. * @name getDaysInYear
  6. * @category Year Helpers
  7. * @summary Get the number of days in a year of the given date.
  8. *
  9. * @description
  10. * Get the number of days in a year of the given date.
  11. *
  12. * ### v2.0.0 breaking changes:
  13. *
  14. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  15. *
  16. * @param {Date|Number} date - the given date
  17. * @returns {Number} the number of days in a year
  18. * @throws {TypeError} 1 argument required
  19. *
  20. * @example
  21. * // How many days are in 2012?
  22. * var result = getDaysInYear(new Date(2012, 0, 1))
  23. * //=> 366
  24. */
  25. export default function getDaysInYear(dirtyDate) {
  26. requiredArgs(1, arguments);
  27. var date = toDate(dirtyDate);
  28. if (isNaN(date)) {
  29. return NaN;
  30. }
  31. return isLeapYear(date) ? 366 : 365;
  32. }