UNPKG

823 BJavaScriptView Raw
1import { millisecondsInSecond } from "./constants.js";
2
3/**
4 * @name millisecondsToSeconds
5 * @category Conversion Helpers
6 * @summary Convert milliseconds to seconds.
7 *
8 * @description
9 * Convert a number of milliseconds to a full number of seconds.
10 *
11 * @param milliseconds - The number of milliseconds to be converted
12 *
13 * @returns The number of milliseconds converted in seconds
14 *
15 * @example
16 * // Convert 1000 milliseconds to seconds:
17 * const result = millisecondsToSeconds(1000)
18 * //=> 1
19 *
20 * @example
21 * // It uses floor rounding:
22 * const result = millisecondsToSeconds(1999)
23 * //=> 1
24 */
25export function millisecondsToSeconds(milliseconds) {
26 const seconds = milliseconds / millisecondsInSecond;
27 return Math.trunc(seconds);
28}
29
30// Fallback for modularized imports:
31export default millisecondsToSeconds;