# roundTime

Industry: Core

## Signature

```ts
roundTime(value: string, options: { smallestUnit: SmallestUnit<TimeUnit>; roundingIncrement?: number; roundingMode?: RoundingMode; }): string
```

Round an ISO 8601 time string to the specified time unit.

- Returns "" for invalid inputs.
- Wraps Temporal.PlainTime.round() which throws on invalid options.
- Output precision follows `smallestUnit`: no fractional seconds for "second" and coarser, 3 digits for "millisecond", 6 for "microsecond" and 9 for "nanosecond", so the result never hides the precision the unit asked for.

## Parameters

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

## Options

**options**

The unit to round to and how to round

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `smallestUnit` | `"hours"` \| `"minutes"` \| `"seconds"` \| `"milliseconds"` \| `"microseconds"` \| `"nanoseconds"` \| `TimeUnit` | Required | The unit to round to, a time unit from `"hour"` to `"nanosecond"`, singular or plural, as Temporal's GetTemporalUnitValuedOption accepts both. It also sets how many fractional-second digits the result is written with. A date unit returns `""`. |
| `roundingIncrement?` | `number` | `1`, Temporal's default. | How many units make one rounding step. Temporal requires it to divide the next larger unit evenly and be smaller than it (`15` minutes, not `7` or `60`), and truncates a non-integer; any other value returns `""`. |
| `roundingMode?` | `"ceil"` \| `"floor"` \| `"expand"` \| `"trunc"` \| `"halfCeil"` \| `"halfFloor"` \| `"halfExpand"` \| `"halfTrunc"` \| `"halfEven"` | `"halfExpand"`, Temporal's default. | Which way a time between two steps goes: one of Temporal's nine rounding modes, such as `"floor"`, `"ceil"` or `"halfExpand"` (to the nearer step, a tie going up). Any other value returns `""`. |

## Returns

Rounded ISO 8601 time string, or "" on invalid input

## Examples

```ts
import { roundTime } from "@northguild/gmt/plain/calculate";

roundTime("12:34:56", { smallestUnit: "hour" }) // "13:00:00"
```

## Source

[plain/calculate/roundTime.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/plain/calculate/roundTime.ts)
