MCPcopy Index your code
hub / github.com/bytebase/bytebase / humanizeDurationV1

Function humanizeDurationV1

frontend/src/utils/util.ts:38–83  ·  view source on GitHub ↗
(duration: Duration | undefined)

Source from the content-addressed store, hash-verified

36}
37
38export const humanizeDurationV1 = (duration: Duration | undefined) => {
39 if (!duration) return "-";
40 const { seconds, nanos } = duration;
41 const totalMs = Number(seconds) * 1000 + nanos / 1e6;
42
43 // For durations less than 1 second, show in milliseconds
44 if (totalMs < 1000) {
45 if (totalMs < 0.01) {
46 return "<0.01ms";
47 }
48 // For sub-10ms, show 2 decimal places for higher precision
49 if (totalMs < 10) {
50 return `${totalMs.toFixed(2)}ms`;
51 }
52 // For 10-100ms, show 1 decimal place
53 if (totalMs < 100) {
54 return `${totalMs.toFixed(1)}ms`;
55 }
56 // For 100ms-1s, show no decimal places
57 return `${totalMs.toFixed(0)}ms`;
58 }
59
60 // For durations between 1-60 seconds, show in seconds with 1 decimal
61 const totalSeconds = totalMs / 1000;
62 if (totalSeconds < 60) {
63 return `${totalSeconds.toFixed(1)}s`;
64 }
65
66 // For durations between 1-60 minutes, show in minutes and seconds
67 const minutes = Math.floor(totalSeconds / 60);
68 if (minutes < 60) {
69 const remainingSeconds = Math.floor(totalSeconds % 60);
70 if (remainingSeconds === 0) {
71 return `${minutes}m`;
72 }
73 return `${minutes}m${remainingSeconds}s`;
74 }
75
76 // For durations over 1 hour, show in hours and minutes
77 const hours = Math.floor(minutes / 60);
78 const remainingMinutes = minutes % 60;
79 if (remainingMinutes === 0) {
80 return `${hours}h`;
81 }
82 return `${hours}h${remainingMinutes}m`;
83};
84
85export function bytesToString(size: number): string {
86 const unitList = ["B", "KB", "MB", "GB", "TB"];

Callers 3

useColumnDefsFunction · 0.90
IssueDetailTaskRunTableFunction · 0.90
PlanDetailTaskRunTableFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected