# DurationStringOptions

Industry: Core

Precision options for the ISO 8601 duration string a `diff*AsDuration` function writes, passed to `Temporal.Duration.prototype.toString()`.

```ts
import type { DurationStringOptions } from "@northguild/gmt";
```

## Members

| Member | Type | Description |
| --- | --- | --- |
| `toStringSmallestUnit?` | `PluralizeUnit<"second" \| "millisecond" \| "microsecond" \| "nanosecond">` | 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"` is refused, as `Temporal.Duration` refuses it. |
| `fractionalSecondDigits?` | `0` \| `1` \| `2` \| `3` \| `4` \| `5` \| `6` \| `7` \| `"auto"` \| `8` \| `9` | 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 `toStringSmallestUnit` is given. |
| `toStringRoundingMode?` | `"ceil"` \| `"floor"` \| `"expand"` \| `"trunc"` \| `"halfCeil"` \| `"halfFloor"` \| `"halfExpand"` \| `"halfTrunc"` \| `"halfEven"` | 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. |

## Definition

```ts
type DurationStringOptions = {
  /**
   * 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"` is refused, as `Temporal.Duration` refuses it.
   *
   * @defaultValue None. The precision comes from `fractionalSecondDigits`.
   */
  toStringSmallestUnit?: ToStringPrecisionOptions["smallestUnit"];
  /**
   * 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
   * `toStringSmallestUnit` is given.
   *
   * @defaultValue `"auto"`, Temporal's default.
   */
  fractionalSecondDigits?: ToStringPrecisionOptions["fractionalSecondDigits"];
  /**
   * 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.
   *
   * @defaultValue `"trunc"`, Temporal's default.
   */
  toStringRoundingMode?: ToStringPrecisionOptions["roundingMode"];
};
```

## Used by

- [`diffDateAsDuration`](/gmt/reference/plain/calculate/diffDateAsDuration/)
- [`diffDateTimeAsDuration`](/gmt/reference/plain/calculate/diffDateTimeAsDuration/)
- [`diffUnixAsDuration`](/gmt/reference/unix/calculate/diffUnixAsDuration/)
- [`diffUtcAsDuration`](/gmt/reference/utc/calculate/diffUtcAsDuration/)
- [`diffZonedAsDuration`](/gmt/reference/zoned/calculate/diffZonedAsDuration/)

## Source

[types/duration-string-options.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/types/duration-string-options.ts)
