getMonth.mjs 742 B

1234567891011121314151617181920212223242526272829
  1. import { toDate } from "./toDate.mjs";
  2. /**
  3. * @name getMonth
  4. * @category Month Helpers
  5. * @summary Get the month of the given date.
  6. *
  7. * @description
  8. * Get the month of the given date.
  9. *
  10. * @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).
  11. *
  12. * @param date - The given date
  13. *
  14. * @returns The month index (0-11)
  15. *
  16. * @example
  17. * // Which month is 29 February 2012?
  18. * const result = getMonth(new Date(2012, 1, 29))
  19. * //=> 1
  20. */
  21. export function getMonth(date) {
  22. const _date = toDate(date);
  23. const month = _date.getMonth();
  24. return month;
  25. }
  26. // Fallback for modularized imports:
  27. export default getMonth;