@sap-cloud-sdk/core
Version:
SAP Cloud SDK for JavaScript core
32 lines • 1.09 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.secondsToTime = exports.timeToSeconds = void 0;
/**
* Converts the given time to seconds in positive numerical format.
* @param time - Time to convert.
* @returns number Time in seconds.
*/
function timeToSeconds(time) {
if (time) {
return Math.floor(time.seconds + time.minutes * 60 + time.hours * 3600);
}
throw Error('The given time is not valid.');
}
exports.timeToSeconds = timeToSeconds;
/**
* Converts from seconds to time as [[Time]].
* @param n - Number of seconds to convert (should be positive).
* @returns Time The converted time from the given number of seconds
*/
function secondsToTime(n) {
if (n <= 0) {
return { hours: 0, minutes: 0, seconds: 0 };
}
var hours = Math.floor(n / 3600);
var restFromHours = n % 3600;
var minutes = Math.floor(restFromHours / 60);
var seconds = restFromHours % 60;
return { hours: hours, minutes: minutes, seconds: seconds };
}
exports.secondsToTime = secondsToTime;
//# sourceMappingURL=time.js.map
;