UNPKG

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