UNPKG

@agentscope/studio

Version:

AgentScope Studio is a powerful local monitoring and visualization tool designed to provide real-time insights into your system's performance and behavior.

87 lines (86 loc) 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeUnixNano = decodeUnixNano; exports.encodeUnixNano = encodeUnixNano; exports.compareISOTimes = compareISOTimes; exports.getEarlierTime = getEarlierTime; exports.getLaterTime = getLaterTime; exports.isValidISOTime = isValidISOTime; exports.getTimeDifference = getTimeDifference; exports.getTimeDifferenceNano = getTimeDifferenceNano; exports.nanoToISOString = nanoToISOString; exports.secondsToNano = secondsToNano; exports.millisecondsToNano = millisecondsToNano; function decodeUnixNano(timeUnixNano) { if (timeUnixNano === null || timeUnixNano === undefined) { return '0'; } if (typeof timeUnixNano === 'number') { return timeUnixNano.toString(); } if (typeof timeUnixNano === 'string') { return timeUnixNano; } // Handle Long type from protobuf if (timeUnixNano && typeof timeUnixNano === 'object') { const longLike = timeUnixNano; if (typeof longLike.toNumber === 'function') { return longLike.toNumber().toString(); } if (typeof longLike.low === 'number' && typeof longLike.high === 'number') { const value = longLike.low + longLike.high * 0x100000000; return value.toString(); } } return '0'; } function encodeUnixNano(isoTimeString) { const milliseconds = new Date(isoTimeString).getTime(); const nanoseconds = milliseconds * 1000000; return nanoseconds.toString(); } function compareISOTimes(time1, time2) { const date1 = new Date(time1); const date2 = new Date(time2); if (date1 < date2) return -1; if (date1 > date2) return 1; return 0; } function getEarlierTime(time1, time2) { return compareISOTimes(time1, time2) <= 0 ? time1 : time2; } function getLaterTime(time1, time2) { return compareISOTimes(time1, time2) >= 0 ? time1 : time2; } function isValidISOTime(timeString) { try { const date = new Date(timeString); return !isNaN(date.getTime()) && timeString === date.toISOString(); } catch (_a) { return false; } } function getTimeDifference(start, end) { const startTime = new Date(start).getTime(); const endTime = new Date(end).getTime(); return endTime - startTime; } function getTimeDifferenceNano(startNano, endNano) { const start = Number(startNano); const end = Number(endNano); return end - start; } function nanoToISOString(nanoTimestamp) { const milliseconds = Number(nanoTimestamp) / 1000000; return new Date(milliseconds).toISOString(); } function secondsToNano(seconds) { return Number(seconds) * 1000000000; } function millisecondsToNano(milliseconds) { return Number(milliseconds) * 1000000; }