cycleZoned
Signature
Section titled “Signature”cycleZoned(value: string, field: DateTimeCycleField, amount: number, options?: { round?: boolean; overflow?: Overflow; disambiguation?: Disambiguation; offset?: Offset; }): stringimport { cycleZoned } from "@northguild/gmt/zoned/calculate";Return a ZonedDateTime ISO string with field cycled by amount, wrapping at that field’s own
- min/max instead of carrying into the next larger field.
cycleZonedis notaddZoned: cycling December’smonthby+1stays in the same year, and cyclinghour23by+1stays on the same day. Reach foraddZonedfor calendar/clock arithmetic; reach forcycleZonedwhen a single field (e.g. a datepicker segment) must stay isolated from the others.- Wrap bounds are computed the same way as
cycleDateTime— plain local-field bounds (houralways0–23, etc.), not DST-aware absolute-time bounds. The wrapped local time is then handed tosetZoned, whose.with()call — viadisambiguationandoffset— resolves whatever DST edge case results (the wrapped local time landing in a gap or an overlap) exactly the way it resolves any other field-set call. This is deliberately simpler than deriving DST-aware wrap boundaries directly. disambiguationdefaults to"compatible"andoffsetdefaults to"ignore"(not Temporal’s own"prefer"default) — the same C3 precedent assetZoned/startOfZoned: with"prefer", the source’s still-valid offset is kept anddisambiguationis silently never consulted. Leaveoffsetat its default unless you specifically need Temporal’s raw.with()semantics.options.roundsteps to the next multiple ofamountin the direction of its sign (ceiling for positive, floor for negative) — not the nearest one. SeecycleDate/cycleTime’s docs for worked examples.- Returns “” for an invalid
valueor an invalidfield.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
zoned ISO 8601 datetime string |
field |
DateTimeCycleField |
the field to cycle: “year” | “month” | “day” | “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 |
— |
disambiguation? |
Disambiguation |
— |
offset? |
Offset |
— |
Returns
Section titled “Returns”zoned ISO 8601 string with field cycled, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”cycleZoned("2024-06-15T09:30:00-05:00[America/Chicago]", "hour", 1) // "2024-06-15T10:30:00-05:00[America/Chicago]"cycleZoned("2024-12-15T09:30:00-06:00[America/Chicago]", "month", 1) // "2024-01-15T09:30:00-06:00[America/Chicago]" (wraps, stays in the same year)cycleZoned("2024-03-10T01:30:00-06:00[America/Chicago]", "hour", 1) // "2024-03-10T03:30:00-05:00[America/Chicago]" (cycled hour lands in a spring-forward gap; "compatible" skips forward)cycleZoned("2024-03-10T01:30:00-06:00[America/Chicago]", "hour", 1, { disambiguation: "reject" }) // "" (same gap; "reject" throws)cycleZoned("2024-06-15T09:30:00-05:00[America/Chicago]", "week", 1) // "" ("week" is not a cyclable field)cycleZoned("invalid", "hour", 1) // ""