previousTuesday.mjs 784 B

123456789101112131415161718192021222324252627
  1. import { previousDay } from "./previousDay.mjs";
  2. /**
  3. * @name previousTuesday
  4. * @category Weekday Helpers
  5. * @summary When is the previous Tuesday?
  6. *
  7. * @description
  8. * When is the previous Tuesday?
  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 date to start counting from
  13. *
  14. * @returns The previous Tuesday
  15. *
  16. * @example
  17. * // When is the previous Tuesday before Jun, 18, 2021?
  18. * const result = previousTuesday(new Date(2021, 5, 18))
  19. * //=> Tue June 15 2021 00:00:00
  20. */
  21. export function previousTuesday(date) {
  22. return previousDay(date, 2);
  23. }
  24. // Fallback for modularized imports:
  25. export default previousTuesday;