setTime
Signature
Section titled “Signature”setTime(value: string, fields: Temporal.PlainTimeLike, options?: { overflow?: Overflow; }): stringimport { setTime } from "@northguild/gmt/plain/calculate";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 — 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 empty object is a no-op.- Returns “” for invalid input.
overflow(“constrain” (default) | “reject”) controls out-of-range field values, e.g.hour: 25: “constrain” clamps to 23, “reject” throws (resulting in “”). UnlikeaddTime(whereoverflowis inert because addition always wraps around the clock),overflowhas a real effect here because.with()assigns fixed field values rather than adding a delta.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO PlainTime string |
fields |
Temporal.PlainTimeLike |
Partial<Temporal.PlainTimeLike> object specifying fields to set |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
overflow? |
Overflow |
— |
Returns
Section titled “Returns”ISO PlainTime string with fields set, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”setTime("12:00:00", { hour: 9 }) // "09:00:00"setTime("12:00:00", { hour: 25 }) // "23:00:00" (constrain clamps to the max valid hour)setTime("12:00:00", { hour: 25 }, { overflow: "reject" }) // ""setTime("12:00:00", {}) // "12:00:00" (empty fields object is a no-op)setTime("invalid", { hour: 9 }) // ""