index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = getDaysInYear;
  6. var _index = _interopRequireDefault(require("../toDate/index.js"));
  7. var _index2 = _interopRequireDefault(require("../isLeapYear/index.js"));
  8. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * @name getDaysInYear
  12. * @category Year Helpers
  13. * @summary Get the number of days in a year of the given date.
  14. *
  15. * @description
  16. * Get the number of days in a year of the given date.
  17. *
  18. * ### v2.0.0 breaking changes:
  19. *
  20. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  21. *
  22. * @param {Date|Number} date - the given date
  23. * @returns {Number} the number of days in a year
  24. * @throws {TypeError} 1 argument required
  25. *
  26. * @example
  27. * // How many days are in 2012?
  28. * const result = getDaysInYear(new Date(2012, 0, 1))
  29. * //=> 366
  30. */
  31. function getDaysInYear(dirtyDate) {
  32. (0, _index3.default)(1, arguments);
  33. var date = (0, _index.default)(dirtyDate);
  34. if (String(new Date(date)) === 'Invalid Date') {
  35. return NaN;
  36. }
  37. return (0, _index2.default)(date) ? 366 : 365;
  38. }
  39. module.exports = exports.default;