setTime
Signature
Section titled “Signature”setTime(value: string, fields: PlainTimeLike, options?: { overflow?: "reject" | "constrain" | undefined; }): stringReturn 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 — seesetDate’s doc for why that matters over composingaddTime()calls field-by-field. fieldsmay set any ofhour,minute,second,millisecond,microsecond, and/ornanosecond; 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,NaNor an infinity returns "" too. An out-of-range number followsoverflow. - An own key that is not one of these fields, such as a misspelt
huor, returns "". So does a date field, such asyear, or acalendarortimeZoneproperty, 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
withrefuses one. One whose prototype has been replaced withObject.prototype,nullorFunction.prototypesets nothing instead. - Unlike
addTime, which takes nooverflowbecause addition always wraps around the clock,overflowhas an effect here:.with()assigns fixed field values rather than adding a delta. - Returns "" for invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainTime string |
fields | PlainTimeLike | Partial<Temporal.PlainTimeLike> object specifying fields to set |
Options
Section titled “Options”options
How an out-of-range field value is handled
| Option | Type | Default | Description |
|---|---|---|---|
overflow? | "reject" | "constrain" (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
Section titled “Returns”ISO PlainTime string with fields set, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { setTime } from "@northguild/gmt/plain/calculate";
setTime("12:00:00", { hour: 9 }) // "09:00:00"