Write a run's elapsed time once, in the duration formatter's units
The runs table drew when a run started and how long it took in two
notations ('56m ago | 55.5 min'), and for a run still going those are the
same reading twice. `dur` now steps past the minute into hours and days,
the ago reading is derived from it, and a running run writes only the
elapsed one.
This commit is contained in:
@@ -38,6 +38,8 @@ assert.equal(dur(0), "0 ms")
|
||||
assert.equal(dur(203.63), "204 ms")
|
||||
assert.equal(dur(1240), "1.24 s")
|
||||
assert.equal(dur(90_000), "1.5 min")
|
||||
assert.equal(dur(12_600_000), "3.5 h")
|
||||
assert.equal(dur(259_200_000), "3 d")
|
||||
|
||||
// The plain window down to 0.01 ms, so a fast run keeps one unit across polls.
|
||||
assert.equal(dur(0.4), "0.4 ms")
|
||||
|
||||
@@ -44,6 +44,8 @@ export function si(value: number, digits = 3): string {
|
||||
|
||||
/** Floor, divisor and unit per step, largest first. */
|
||||
const DUR_STEPS: [number, number, string][] = [
|
||||
[86_400_000, 86_400_000, "d"],
|
||||
[3_600_000, 3_600_000, "h"],
|
||||
[60_000, 60_000, "min"],
|
||||
[1_000, 1_000, "s"],
|
||||
[0.01, 1, "ms"],
|
||||
@@ -63,6 +65,9 @@ const DUR_STEPS: [number, number, string][] = [
|
||||
* window transposed onto units. That floor is deliberate: without it a tile
|
||||
* polled every ten seconds flips between "400 µs" and "1.2 ms", and a reading
|
||||
* that changes unit on every poll reads as broken rather than as fast.
|
||||
*
|
||||
* It keeps stepping past the minute into hours and days, so that an elapsed
|
||||
* time is one notation wherever it is written — "3.5 h", never "210 min".
|
||||
*/
|
||||
export function dur(ms: number, digits = 3): string {
|
||||
if (!Number.isFinite(ms)) return "--"
|
||||
|
||||
Reference in New Issue
Block a user