azure-kusto-data
Version:
Azure Data Explorer Query SDK
23 lines • 919 B
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export function toMilliseconds(hours, minutes, seconds) {
return (hours * 60 * 60 + minutes * 60 + seconds) * 1000;
}
// Format: [+|-]d.hh:mm:ss[.fffffff]
const TimespanRegex = /^(-?)(?:(\d+).)?(\d{2}):(\d{2}):(\d{2}(\.\d+)?$)/;
export function parseKustoTimestampToMillis(t) {
if (t == null || t === "") {
return null;
}
const match = TimespanRegex.exec(t);
if (match) {
const sign = match[1] === "-" ? -1 : 1;
const days = parseInt(match[2] || "0", 10);
const hours = parseInt(match[3], 10);
const minutes = parseInt(match[4], 10);
const seconds = parseFloat(match[5]);
return sign * 1000 * (days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60 + seconds);
}
throw new Error(`Timespan value '${t}' cannot be decoded`);
}
//# sourceMappingURL=timeUtils.js.map