getYear.js 656 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. exports.getYear = getYear;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name getYear
  6. * @category Year Helpers
  7. * @summary Get the year of the given date.
  8. *
  9. * @description
  10. * Get the year of the given date.
  11. *
  12. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  13. *
  14. * @param date - The given date
  15. *
  16. * @returns The year
  17. *
  18. * @example
  19. * // Which year is 2 July 2014?
  20. * const result = getYear(new Date(2014, 6, 2))
  21. * //=> 2014
  22. */
  23. function getYear(date) {
  24. return (0, _index.toDate)(date).getFullYear();
  25. }