MCPcopy Create free account
hub / github.com/tensorflow/tensorboard / formatRelativeTimeInMs

Function formatRelativeTimeInMs

tensorboard/webapp/util/value_formatter.ts:24–51  ·  view source on GitHub ↗
(timeInMs: number)

Source from the content-addressed store, hash-verified

22 * "10h 33m 17s"
23 */
24export function formatRelativeTimeInMs(timeInMs: number): string {
25 // We will always show 2 units of precision, e.g days and hours, or
26 // minutes and seconds, but not hours and minutes and seconds.
27 const result: string[] = [];
28 const timeInHours = timeInMs / (1000 * 60 * 60);
29 const days = Math.floor(timeInHours / 24);
30 if (days) {
31 result.push(days.toString() + 'd');
32 }
33
34 const remainingHours = timeInHours - days * 24;
35 const hours = Math.floor(remainingHours);
36 if (hours || days) {
37 result.push(hours.toString() + 'h');
38 }
39
40 const remainingMinutes = (remainingHours - hours) * 60;
41 const minutes = Math.floor(remainingMinutes);
42 if (minutes || hours || days) {
43 result.push(minutes.toString() + 'm');
44 }
45
46 const remainingSeconds = (remainingMinutes - minutes) * 60;
47 const seconds = Math.floor(remainingSeconds);
48 result.push(seconds.toString() + 's');
49
50 return result.join(' ');
51}
52
53/**
54 * Integers less than this number can be safely formatted as-is.

Callers 1

Calls 3

pushMethod · 0.45
toStringMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…