# parseDuration

Industry: Core

## Signature

```ts
parseDuration(value: string, options?: { smallestUnit?: PluralizeUnit<"second" | "millisecond" | "microsecond" | "nanosecond"> | undefined; fractionalSecondDigits?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | "auto" | 8 | 9 | undefined; roundingMode?: "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven" | undefined; }): string
```

Parse and re-normalize an ISO 8601 duration string.

- Uses Temporal.Duration.from to parse, then .toString() to re-emit.
- Returns "" for invalid input.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | ISO 8601 duration string |

## Options

**options**

The precision of the string written back, as Temporal's ToStringPrecisionOptions

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `smallestUnit?` | `PluralizeUnit<"second" \| "millisecond" \| "microsecond" \| "nanosecond">` | None. The precision comes from `fractionalSecondDigits`. | The smallest unit written in the string: `"second"`, `"millisecond"`, `"microsecond"` or `"nanosecond"`. It sets how many fractional-second digits appear and takes precedence over `fractionalSecondDigits`. `"minute"` returns `""`, as `Temporal.Duration` refuses it. |
| `fractionalSecondDigits?` | `0` \| `1` \| `2` \| `3` \| `4` \| `5` \| `6` \| `7` \| `"auto"` \| `8` \| `9` | `"auto"`, Temporal's default. | The number of fractional-second digits written: `0` to `9` writes exactly that many, and `"auto"` writes as many as the duration needs, with no trailing zeros. It has no effect when `smallestUnit` is given. |
| `roundingMode?` | `"ceil"` \| `"floor"` \| `"expand"` \| `"trunc"` \| `"halfCeil"` \| `"halfFloor"` \| `"halfExpand"` \| `"halfTrunc"` \| `"halfEven"` | `"trunc"`, Temporal's default. | How the duration is rounded when the precision asked for drops digits. `"trunc"` cuts them off; `"halfExpand"` rounds to the nearest value, a half going away from zero. |

## Returns

re-normalized ISO 8601 duration string, or "" on invalid input

## Examples

```ts
import { parseDuration } from "@northguild/gmt/duration/parse";

parseDuration("P1DT2H30M") // "P1DT2H30M"
```

## Source

[duration/parse/parseDuration.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/duration/parse/parseDuration.ts)
