getYear.js 604 B

123456789101112131415161718192021222324252627282930
  1. import { toDate } from "./toDate.js";
  2. /**
  3. * The {@link getYear} function options.
  4. */
  5. /**
  6. * @name getYear
  7. * @category Year Helpers
  8. * @summary Get the year of the given date.
  9. *
  10. * @description
  11. * Get the year of the given date.
  12. *
  13. * @param date - The given date
  14. * @param options - An object with options
  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. export function getYear(date, options) {
  24. return toDate(date, options?.in).getFullYear();
  25. }
  26. // Fallback for modularized imports:
  27. export default getYear;