index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = getDayOfYear;
  6. var _index = _interopRequireDefault(require("../toDate/index.js"));
  7. var _index2 = _interopRequireDefault(require("../startOfYear/index.js"));
  8. var _index3 = _interopRequireDefault(require("../differenceInCalendarDays/index.js"));
  9. var _index4 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. /**
  12. * @name getDayOfYear
  13. * @category Day Helpers
  14. * @summary Get the day of the year of the given date.
  15. *
  16. * @description
  17. * Get the day of the year of the given date.
  18. *
  19. * ### v2.0.0 breaking changes:
  20. *
  21. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  22. *
  23. * @param {Date|Number} date - the given date
  24. * @returns {Number} the day of year
  25. * @throws {TypeError} 1 argument required
  26. *
  27. * @example
  28. * // Which day of the year is 2 July 2014?
  29. * const result = getDayOfYear(new Date(2014, 6, 2))
  30. * //=> 183
  31. */
  32. function getDayOfYear(dirtyDate) {
  33. (0, _index4.default)(1, arguments);
  34. var date = (0, _index.default)(dirtyDate);
  35. var diff = (0, _index3.default)(date, (0, _index2.default)(date));
  36. var dayOfYear = diff + 1;
  37. return dayOfYear;
  38. }
  39. module.exports = exports.default;