Skip to main content
Glama
time.ts683 B
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 export type TimeUnit = 'ns' | 'µs' | 'ms' | 's'; const PREFIXES: TimeUnit[] = ['ns', 'µs', 'ms', 's']; export function formatDuration(ns: number | undefined, from: TimeUnit = 'ns', precision = 3): string { if (!ns) { return '-'; } const magnitude = Math.floor(Math.log10(ns) / 3); let time = 0; if (magnitude < 0) { time = ns * 10 ** (3 * -magnitude); } else if (magnitude >= 1) { time = ns / 10 ** (3 * magnitude); } else { time = ns; } return `${time.toPrecision(precision)} ${PREFIXES[magnitude + PREFIXES.indexOf(from)]}`; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/medplum/medplum'

If you have feedback or need assistance with the MCP directory API, please join our Discord server