MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / formatDuration

Function formatDuration

frontend/packages/dashboard/src/utils/dashboard.ts:154–168  ·  view source on GitHub ↗
(durationNano: number)

Source from the content-addressed store, hash-verified

152 * @returns 格式化后的字符串,包含单位
153 */
154export function formatDuration(durationNano: number) {
155 if (durationNano < 1000) {
156 return `${durationNano}ms` // 小于1000,返回毫秒
157 }
158 if (durationNano < 1_000_000) {
159 return (durationNano / 1000).toFixed(1) + 's' // 转换为秒
160 }
161 if (durationNano < 1_000_000_000) {
162 return (durationNano / 1_000_000).toFixed(1) + 'min' // 转换为分钟
163 }
164 if (durationNano < 1_000_000_000_000) {
165 return (durationNano / 1_000_000_000).toFixed(1) + 'hour' // 转换为小时
166 }
167 return (durationNano / 1_000_000_000_000).toFixed(1) + 'day' // 转换为天
168}
169
170/**
171 * 格式化数据大小,自动选择合适的单位

Callers 2

setRestChartInfoDataFunction · 0.90
setRestChartInfoDataFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected