# setTime

Industry: Core

## Signature

```ts
setTime(value: string, fields: PlainTimeFields, options?: { overflow?: "reject" | "constrain" | undefined; }): string
```

Return a PlainTime ISO string with the given `fields` set on `value`.

- Wraps `Temporal.PlainTime.prototype.with()`, which resolves every supplied field in a single atomic overflow pass — see `setDate`'s doc for why that matters over composing `addTime()` calls field-by-field.
- `fields` may set any of `hour`, `minute`, `second`, `millisecond`, `microsecond`, and/or `nanosecond`; omitted fields keep their current value. An object with no field set, such as `{}` or `{ hour: undefined }`, is a no-op.
- Values are not converted: all six fields must be integer numbers. `null`, a numeric string, a boolean or a fraction returns "", where Temporal would convert or truncate it. A bigint, `NaN` or an infinity returns "" too. An out-of-range number follows `overflow`.
- An own key that is not one of these fields, such as a misspelt `huor`, returns "". So does a date field, such as `year`, or a `calendar` or `timeZone` property, whether own, inherited or a getter. A field is read with a property get, as Temporal reads it, so an inherited or getter field is set.
- A Temporal date or time object returns "", as Temporal's `with` refuses one. One whose prototype has been replaced with `Object.prototype`, `null` or `Function.prototype` sets nothing instead.
- Unlike `addTime`, which takes no `overflow` because addition always wraps around the clock, `overflow` has an effect here: `.with()` assigns fixed field values rather than adding a delta.
- Returns "" for invalid input.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | ISO PlainTime string |
| `fields` | `PlainTimeFields` | Partial&lt;Temporal.PlainTimeLike&gt; object specifying fields to set |

## Options

**options**

How an out-of-range field value is handled

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `overflow?` | `"reject"` \| `"constrain"` ([`Overflow`](/gmt/reference/types/Overflow/)) | `"constrain"`, Temporal's default. | What to do when a field value is out of range. `"constrain"` clamps it to the nearest valid value, so `hour: 25` becomes 23; `"reject"` returns `""`. |

## Returns

ISO PlainTime string with fields set, or "" on invalid input

## Related types

- [`Overflow`](/gmt/reference/types/Overflow/)

## Examples

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

setTime("12:00:00", { hour: 9 }) // "09:00:00"
```

## Source

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