subHours.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { addHours } from "./addHours.js";
  2. /**
  3. * The {@link subHours} function options.
  4. */
  5. /**
  6. * @name subHours
  7. * @category Hour Helpers
  8. * @summary Subtract the specified number of hours from the given date.
  9. *
  10. * @description
  11. * Subtract the specified number of hours from the given date.
  12. *
  13. * @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).
  14. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  15. *
  16. * @param date - The date to be changed
  17. * @param amount - The amount of hours to be subtracted.
  18. * @param options - The options
  19. *
  20. * @returns The new date with the hours subtracted
  21. *
  22. * @example
  23. * // Subtract 2 hours from 11 July 2014 01:00:00:
  24. * const result = subHours(new Date(2014, 6, 11, 1, 0), 2)
  25. * //=> Thu Jul 10 2014 23:00:00
  26. */
  27. export function subHours(date, amount, options) {
  28. return addHours(date, -amount, options);
  29. }
  30. // Fallback for modularized imports:
  31. export default subHours;