Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat: improve display of time intervals

Marc Klingen0e433b5f5c65
diff --git a/src/utils/dates.ts b/src/utils/dates.ts
index 88793620df..03372cf4b9 100644
--- a/src/utils/dates.ts
+++ b/src/utils/dates.ts
@@ -22,19 +22,9 @@ export const formatInterval = (seconds: number) => {
const hrs = Math.floor(seconds / 3600);
const mins = Math.floor((seconds % 3600) / 60);
const secs = Math.floor(seconds % 60);
- const ms = Math.floor((seconds % 1) * 1000);
+ const pad = (num: number) => `00${num}`.slice(2);
- const pad = (num: number, digits?: number) =>
- `${"0".repeat(digits ?? 2)}${num}`.slice(-(digits ?? 2));
- return (
- `${pad(hrs)}:${pad(mins)}:${pad(secs)}.${pad(ms, 3)}`
- // dynamically remove leading zeros
- .replace(/^0+:/, "")
- .replace(/^0+:/, "")
- // if the time is less than 1 minute, remove the leading zeros from the seconds
- // make sure to only match 00.xxx and not 00:00.xxx
- .replace(/^00\./, "0.") +
- // if the time is less than 1 minute, add a s at the end
- (seconds < 60 ? "s" : "")
- );
+ if (hrs > 0) return `${hrs}h ${pad(mins)}m ${pad(secs)}s`;
+ if (mins > 0) return `${mins}m ${pad(secs)}s`;
+ return `${seconds.toFixed(2)}s`;
};