previousDay.d.cts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import type { ContextOptions, DateArg, Day } from "./types.js";
  2. /**
  3. * The {@link previousDay} function options.
  4. */
  5. export interface PreviousDayOptions<DateType extends Date = Date>
  6. extends ContextOptions<DateType> {}
  7. /**
  8. * @name previousDay
  9. * @category Weekday Helpers
  10. * @summary When is the previous day of the week?
  11. *
  12. * @description
  13. * When is the previous day of the week? 0-6 the day of the week, 0 represents Sunday.
  14. *
  15. * @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).
  16. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  17. *
  18. * @param date - The date to check
  19. * @param day - The day of the week
  20. * @param options - An object with options
  21. *
  22. * @returns The date is the previous day of week
  23. *
  24. * @example
  25. * // When is the previous Monday before Mar, 20, 2020?
  26. * const result = previousDay(new Date(2020, 2, 20), 1)
  27. * //=> Mon Mar 16 2020 00:00:00
  28. *
  29. * @example
  30. * // When is the previous Tuesday before Mar, 21, 2020?
  31. * const result = previousDay(new Date(2020, 2, 21), 2)
  32. * //=> Tue Mar 17 2020 00:00:00
  33. */
  34. export declare function previousDay<
  35. DateType extends Date,
  36. ResultDate extends Date = DateType,
  37. >(
  38. date: DateArg<DateType>,
  39. day: Day,
  40. options?: PreviousDayOptions<ResultDate> | undefined,
  41. ): ResultDate;