Skip to content

roundZoned

roundZoned(value: string, options: { smallestUnit: Temporal.SmallestUnit<"day" | "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond">; roundingIncrement?: number; roundingMode?: Temporal.RoundingMode; }): string
import { roundZoned } from "@northguild/gmt/zoned/calculate";

Round an ISO 8601 zoned datetime string to the specified unit.

  • Returns “” for invalid inputs.
  • Accepts “day” and time units: “hour”, “minute”, “second”, “millisecond”, “microsecond”, “nanosecond”.
  • Date units (“year”, “month”, “week”) are not supported by the Temporal polyfill’s ZonedDateTime.round() — they return “”.
  • Wraps Temporal.ZonedDateTime.round() which throws on invalid options.
  • Note: The polyfill’s .round() does not support disambiguation or offset options.
Parameter Type Description
value string ISO 8601 zoned datetime string

options

Option Type Default
smallestUnit Temporal.SmallestUnit&lt;"day" | "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond"&gt;
roundingIncrement? number
roundingMode? Temporal.RoundingMode

Rounded ISO 8601 zoned datetime string, or “” on invalid input

roundZoned("2024-06-15T12:34:56-05:00[America/New_York]", { smallestUnit: "hour" }) // "2024-06-15T13:00:00-05:00[America/New_York]"
roundZoned("2024-06-15T12:34:56-05:00[America/New_York]", { smallestUnit: "minute", roundingIncrement: 15 }) // "2024-06-15T12:45:00-05:00[America/New_York]"
roundZoned("invalid", { smallestUnit: "hour" }) // ""

zoned/calculate/roundZoned.ts