> For AI agents: the complete documentation index is available at https://wallarm.github.io/design-system/llms.txt, the full documentation bundle is available at https://wallarm.github.io/design-system/llms-full.txt.

# FormatDuration

Prints how long something took in its two largest units — `1h 30m`, `30m 23s`, `45s` — so a column of run times stays short and comparable. When smaller units are dropped, the exact duration sits in a tooltip behind a dashed underline. `value` takes milliseconds or an ISO 8601 duration (`PT2M13S`); `formatDuration()` returns the same text as a string.

[Source](https://github.com/wallarm/design-system/tree/main/packages/design-system/src/components/FormatDuration) · [Storybook](https://wallarm.github.io/design-system/storybook/?path=/docs/data-display-formatduration--overview)

```tsx
import { FormatDuration } from '@wallarm-org/design-system/FormatDuration';

export const Units = () => (
  <div className='grid grid-cols-[1fr_1fr] items-center gap-x-16 gap-y-12'>
    <FormatDuration value={0} data-testid='duration-zero' />
    <FormatDuration value={300} data-testid='duration-sub-second' />
    <FormatDuration value={45_000} data-testid='duration-seconds' />
    <FormatDuration value={1_823_000} data-testid='duration-minutes' />
    <FormatDuration value={3_600_000} data-testid='duration-hour' />
    <FormatDuration value={5_400_000} data-testid='duration-hours' />
    <FormatDuration value={184_500_000} data-testid='duration-days' />
  </div>
);
```

## Usage

```tsx
import { FormatDuration } from '@wallarm-org/design-system/FormatDuration';
```

## Examples

### Truncated

Two units are shown; the rest moves into the tooltip, so `1h 4m 30s` reads `1h 4m`
with the exact figure on hover. `tooltip={false}` drops the tooltip and the underline.

```tsx
import { FormatDuration } from '@wallarm-org/design-system/FormatDuration';

export const Truncated = () => (
  <div className='grid grid-cols-[1fr_1fr] items-center gap-x-16 gap-y-12'>
    <FormatDuration value={3_870_000} data-testid='duration-truncated' />
    <FormatDuration value={184_500_000} data-testid='duration-truncated-days' />
    <FormatDuration value={3_870_000} tooltip={false} data-testid='duration-no-tooltip' />
  </div>
);
```

### Iso duration

An ISO 8601 duration from an API contract renders as is, without converting it first.

```tsx
import { FormatDuration } from '@wallarm-org/design-system/FormatDuration';

export const IsoDuration = () => (
  <div className='grid grid-cols-[1fr_1fr] items-center gap-x-16 gap-y-12'>
    <FormatDuration value='PT52S' />
    <FormatDuration value='PT2M13S' />
    <FormatDuration value='PT41.6S' />
    <FormatDuration value='P1DT2H' />
  </div>
);
```

### Null value

`null` and `undefined` render an em dash with 'No data' on hover; a negative or
unparsable value renders a bare em dash.

```tsx
import { FormatDuration } from '@wallarm-org/design-system/FormatDuration';

export const NullValue = () => (
  <div className='grid grid-cols-[1fr_1fr] items-center gap-x-16 gap-y-12'>
    <FormatDuration value={null} data-testid='duration-null' />
    <FormatDuration value={-1000} />
    <FormatDuration value='2 minutes' />
  </div>
);
```

### Inherit typography

`typography='inherit'` renders a plain span, so the duration takes its font, size,
weight and colour from the parent.

```tsx
import { FormatDuration } from '@wallarm-org/design-system/FormatDuration';

export const InheritTypography = () => (
  <div className='font-sans-display text-xl font-medium text-text-primary'>
    <FormatDuration value={1_823_000} typography='inherit' />
  </div>
);
```

## Props

| Prop           | Type                                                 | Default   | Description                                                                                                                                                           |
| -------------- | ---------------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| title          | `string \| undefined`                                |           |                                                                                                                                                                       |
| defaultChecked | `boolean \| undefined`                               |           |                                                                                                                                                                       |
| defaultValue   | `string \| number \| readonly string[] \| undefined` |           |                                                                                                                                                                       |
| autoFocus      | `boolean \| undefined`                               |           |                                                                                                                                                                       |
| id             | `string \| undefined`                                |           |                                                                                                                                                                       |
| tabIndex       | `number \| undefined`                                |           |                                                                                                                                                                       |
| rel            | `string \| undefined`                                |           |                                                                                                                                                                       |
| onChange       | `ChangeEventHandler<T, Element> \| undefined`        |           |                                                                                                                                                                       |
| value \*       | `DurationValue`                                      |           | Milliseconds, or an ISO 8601 duration ("PT2M13S"). null/undefined renders an em dash with a "No data" tooltip; a negative or unparsable value renders a bare em dash. |
| tooltip        | `boolean \| undefined`                               |           | Whether to show the exact duration in a tooltip when smaller units were dropped ("1h 4m" → "1h 4m 30s"). Default: true.                                               |
| typography     | `"inherit" \| "default" \| undefined`                | `default` | 'default' renders 14px body text; 'inherit' takes font, size and colour from the parent. Default: 'default'.                                                          |
| data-testid    | `string \| undefined`                                |           |                                                                                                                                                                       |
