UNPKG

@sap-cloud-sdk/odata-common

Version:

SAP Cloud SDK for JavaScript common functions of OData client generator and OpenAPI clint generator.

45 lines 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.durationRegexV4 = exports.durationRegexV2 = void 0; exports.timeToSeconds = timeToSeconds; exports.secondsToTime = secondsToTime; /** * @internal */ exports.durationRegexV2 = /PT(?<hours>\d{1,2}H)?(?<minutes>\d{1,2}M)?(?<seconds>\d{1,2}S)?/; /** * Spec see here https://www.w3.org/TR/xmlschema11-2/#nt-duDTFrag * Regex see here https://regex101.com/r/sxO6YO/1 * Matches a spec compliant duration like -P5DT12H30M12.9S * @internal */ exports.durationRegexV4 = /^([+-])?P(\d+D)?(T(\d+H)?(\d+M)?(\d+(\.\d+)?S)?)?$/; /** * Converts the given time to seconds in positive numerical format. * @param time - Time to convert. * @returns number Time in seconds. * @internal */ function timeToSeconds(time) { if (time) { return Math.floor(time.seconds + time.minutes * 60 + time.hours * 3600); } throw Error('The given time is not valid.'); } /** * Converts from seconds to time as {@link Time}. * @param n - Number of seconds to convert (should be positive). * @returns Time The converted time from the given number of seconds * @internal */ function secondsToTime(n) { if (n <= 0) { return { hours: 0, minutes: 0, seconds: 0 }; } const hours = Math.floor(n / 3600); const restFromHours = n % 3600; const minutes = Math.floor(restFromHours / 60); const seconds = restFromHours % 60; return { hours, minutes, seconds }; } //# sourceMappingURL=time.js.map