UNPKG

1.09 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.secondsToTime = exports.timeToSeconds = void 0;
4/**
5 * Converts the given time to seconds in positive numerical format.
6 * @param time - Time to convert.
7 * @returns number Time in seconds.
8 */
9function timeToSeconds(time) {
10 if (time) {
11 return Math.floor(time.seconds + time.minutes * 60 + time.hours * 3600);
12 }
13 throw Error('The given time is not valid.');
14}
15exports.timeToSeconds = timeToSeconds;
16/**
17 * Converts from seconds to time as [[Time]].
18 * @param n - Number of seconds to convert (should be positive).
19 * @returns Time The converted time from the given number of seconds
20 */
21function secondsToTime(n) {
22 if (n <= 0) {
23 return { hours: 0, minutes: 0, seconds: 0 };
24 }
25 var hours = Math.floor(n / 3600);
26 var restFromHours = n % 3600;
27 var minutes = Math.floor(restFromHours / 60);
28 var seconds = restFromHours % 60;
29 return { hours: hours, minutes: minutes, seconds: seconds };
30}
31exports.secondsToTime = secondsToTime;
32//# sourceMappingURL=time.js.map
\No newline at end of file