hoursToSeconds.mjs 779 B

123456789101112131415161718192021222324252627
  1. import { secondsInHour } from "./constants.mjs";
  2. /**
  3. * @name hoursToSeconds
  4. * @category Conversion Helpers
  5. * @summary Convert hours to seconds.
  6. *
  7. * @description
  8. * Convert a number of hours to a full number of seconds.
  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 hours - The number of hours to be converted
  13. *
  14. * @returns The number of hours converted in seconds
  15. *
  16. * @example
  17. * // Convert 2 hours to seconds:
  18. * const result = hoursToSeconds(2)
  19. * //=> 7200
  20. */
  21. export function hoursToSeconds(hours) {
  22. return Math.trunc(hours * secondsInHour);
  23. }
  24. // Fallback for modularized imports:
  25. export default hoursToSeconds;