MCPcopy Index your code
hub / github.com/nodejs/node / formatTime

Function formatTime

lib/internal/util/debuglog.js:153–185  ·  view source on GitHub ↗
(ms)

Source from the content-addressed store, hash-verified

151const kHour = 60 * kMinute;
152
153function formatTime(ms) {
154 let hours = 0;
155 let minutes = 0;
156 let seconds = 0;
157
158 if (ms >= kSecond) {
159 if (ms >= kMinute) {
160 if (ms >= kHour) {
161 hours = MathFloor(ms / kHour);
162 ms = ms % kHour;
163 }
164 minutes = MathFloor(ms / kMinute);
165 ms = ms % kMinute;
166 }
167 seconds = ms / kSecond;
168 }
169
170 if (hours !== 0 || minutes !== 0) {
171 ({ 0: seconds, 1: ms } = StringPrototypeSplit(
172 NumberPrototypeToFixed(seconds, 3),
173 '.',
174 2,
175 ));
176 const res = hours !== 0 ? `${hours}:${pad(minutes)}` : minutes;
177 return `${res}:${pad(seconds)}.${ms} (${hours !== 0 ? 'h:m' : ''}m:ss.mmm)`;
178 }
179
180 if (seconds !== 0) {
181 return `${NumberPrototypeToFixed(seconds, 3)}s`;
182 }
183
184 return `${Number(NumberPrototypeToFixed(ms, 3))}ms`;
185}
186
187function safeTraceLabel(label) {
188 return label.replaceAll('\\', '\\\\').replaceAll('"', '\\"');

Callers 2

timeLogImplFunction · 0.85

Calls 1

padFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…