duration Renderer
renderAs: 'duration' converts a numeric duration value to a human-friendly string. The unit option is required to specify the unit of the raw number. Three output formats are available: humanized, clock, and decimal.
Core Examples
Humanized
format: 'humanized' (the default) breaks the duration into its largest named components. precision limits how many components appear:
Millisecond durations shown as humanized text. Default precision is 2 (e.g. '1 day 2 hours'); precision 1 shows only the largest unit.
{ renderAs: 'duration', renderAsOptions: { unit: 'ms', format: 'humanized' } } // "1 day 2 hours"
{ renderAs: 'duration', renderAsOptions: { unit: 'ms', format: 'humanized', precision: 1 } } // "1 day"
Clock Format
format: 'clock' outputs HH:MM:SS. Useful for build times, lap times, and other measured intervals:
Second and millisecond durations in HH:MM:SS clock format.
{ renderAs: 'duration', renderAsOptions: { unit: 'sec', format: 'clock' } } // "0:02:25"
{ renderAs: 'duration', renderAsOptions: { unit: 'ms', format: 'clock' } } // "26:00:00"
Decimal Format
format: 'decimal' expresses the duration as a decimal number in the input unit. showSign: true adds a + prefix for positive values:
Lag values in decimal. Right column shows sign control — positive gets '+', negative shows '-'.
{ renderAs: 'duration', renderAsOptions: { unit: 'ms', format: 'decimal', formatOptions: { maximumFractionDigits: 2 } } }
{ renderAs: 'duration', renderAsOptions: { unit: 'ms', format: 'decimal', showSign: true } }
Custom Humanized Units
humanizedUnits restricts which components appear in humanized output. Useful to suppress days or seconds:
Same response-time values with default units vs. hours + minutes only.
{ renderAs: 'duration', renderAsOptions: { unit: 'ms', format: 'humanized' } }
{ renderAs: 'duration', renderAsOptions: { unit: 'ms', format: 'humanized', humanizedUnits: ['hour', 'minute'] } }
Options Reference
| Option | Type | Default | Effect |
|---|---|---|---|
unit | DurationUnit | required | Unit of the raw input value. |
format | 'humanized' | 'clock' | 'decimal' | 'humanized' | Output format. |
precision | number | 2 | humanized only — maximum number of components to show. |
showSign | boolean | false | decimal only — prefix positive values with +. |
humanizedUnits | DurationHumanizedUnit[] | ['day','hour','minute','second'] | humanized only — allowed component units. |
formatOptions | Intl.NumberFormatOptions | unset | decimal only — passed to Intl.NumberFormat for the decimal number. |
fallbackText | string | 'Invalid' | Text shown when the value is not a finite number. |
className | string | unset | Additional CSS class on the root element. |
DurationUnit values
| Value | Interprets raw number as |
|---|---|
'ms' | Milliseconds |
'sec' | Seconds |
'min' | Minutes |
'hour' | Hours |
'day' | Days |
DurationHumanizedUnit values
'year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond'
Caveats
unitis required. Without it the renderer cannot convert the raw number and outputsfallbackText.format: 'humanized'usesprecision(default 2) to limit output to the largest N components. A value of3600001ms withprecision: 1shows"1 hour", not"1 hour 1 millisecond".- Year and month are approximations: 1 year = 365 days, 1 month = 30 days.
format: 'clock'always producesHH:MM:SSwith no sign prefix, even for negative values.showSign: trueonly affectsformat: 'decimal'. Forhumanized, negatives show a leading-; forclock, sign is not shown.- All options accept
(entity) => valuefunctions for per-row dynamic values.