Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

35 строки
972 B

  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. }