getDay.mjs 774 B

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