cycleTime
Signature
Section titled “Signature”cycleTime(value: string, field: TimeCycleField, amount: number, options?: { round?: boolean; overflow?: Overflow; }): stringimport { cycleTime } from "@northguild/gmt/plain/calculate";Return 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 (
hour23+1wraps to0, it never changes a date —cycleTimehas 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.options.rounddoes not round to the nearest increment — it steps to the next multiple ofamountin the direction of its sign (ceiling for positive, floor for negative), matching@internationalized/date’sCycleOptions.round. E.g. cycling minute22by+15withround: truelands on30(the next multiple of 15 above 22), not15(the nearest one).options.overflowis accepted for signature consistency withcycleDate/cycleDateTime/cycleZonedbut is inert here: time fields don’t share bounds the waydayshares a month withmonth/year, so the wrapped valuecycleTimecomputes is always already valid —setTime’s.with()call never has anything to constrain or reject.- Returns “” for an invalid
valueor an invalidfield.
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
| Option | Type | Default |
|---|---|---|
round? |
boolean |
— |
overflow? |
Overflow |
— |
Returns
Section titled “Returns”ISO PlainTime string with field cycled, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”cycleTime("09:30:00", "hour", 1) // "10:30:00"cycleTime("23:00:00", "hour", 1) // "00:00:00" (wraps)cycleTime("00:00:00", "hour", 25) // "01:00:00" (amount larger than the range)cycleTime("09:22:00", "minute", 15, { round: true }) // "09:30:00"cycleTime("09:30:00", "year", 1) // "" ("year" is not a cyclable time field)cycleTime("invalid", "hour", 1) // ""