cycleTime
Signature
Section titled “Signature”cycleTime(value: string, field: TimeCycleField, amount: number, options?: { round?: boolean; }): stringReturn a PlainTime ISO string with field cycled by amount, wrapping at that field’s own min/max instead of carrying into the next larger field (hour 23 +1 wraps to 0, it never changes a date — cycleTime has no date component to carry into in the first place).
houralways cycles0–23. GMT has nohourCycle: 12option — a 12-hour, AM/PM-preserving wrap is a display/formatting concern (locale-driven, viaIntl), not a value-layer one: there is no ISO representation for “this hour, but staying AM” to round-trip through GMT’s string contract.minute/secondwrap0–59;millisecond/microsecond/nanosecondwrap0–999.- With
round: true, minute22by+15lands on30, the next multiple of 15 above 22, not on15, the nearest one. - There is no
overflowoption (removed in 1.16.0): time fields don’t share bounds the waydayshares a month withmonth/year, so the wrapped value is always already valid and there is nothing to constrain or reject. - Returns "" for an invalid
value, an invalidfield, or anamountthat is not a finite number.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainTime string |
field | TimeCycleField | the field to cycle: “hour” | “minute” | “second” | “millisecond” | “microsecond” | “nanosecond” |
amount | number | signed amount to cycle by |
Options
Section titled “Options”options
How the field is stepped
| Option | Type | Default | Description |
|---|---|---|---|
round? | boolean | false | Whether to step to a multiple of amount instead of adding it. true moves to the next multiple in the direction of the sign of amount (the ceiling for a positive amount, the floor for a negative one), not to the nearest one; false adds amount. |
Returns
Section titled “Returns”ISO PlainTime string with field cycled, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { cycleTime } from "@northguild/gmt/plain/calculate";
cycleTime("09:30:00", "hour", 1) // "10:30:00"