index.js 597 B

1234567891011121314151617181920212223
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name getYear
  5. * @category Year Helpers
  6. * @summary Get the year of the given date.
  7. *
  8. * @description
  9. * Get the year of the given date.
  10. *
  11. * @param {Date|Number} date - the given date
  12. * @returns {Number} the year
  13. * @throws {TypeError} 1 argument required
  14. *
  15. * @example
  16. * // Which year is 2 July 2014?
  17. * const result = getYear(new Date(2014, 6, 2))
  18. * //=> 2014
  19. */
  20. export default function getYear(dirtyDate) {
  21. requiredArgs(1, arguments);
  22. return toDate(dirtyDate).getFullYear();
  23. }