roundZoned
Signature
Section titled “Signature”roundZoned(value: string, options: { smallestUnit: Temporal.SmallestUnit<"day" | "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond">; roundingIncrement?: number; roundingMode?: Temporal.RoundingMode; }): stringimport { 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 supportdisambiguationoroffsetoptions.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO 8601 zoned datetime string |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
smallestUnit |
Temporal.SmallestUnit<"day" | "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond"> |
— |
roundingIncrement? |
number |
— |
roundingMode? |
Temporal.RoundingMode |
— |
Returns
Section titled “Returns”Rounded ISO 8601 zoned datetime string, or “” on invalid input
Examples
Section titled “Examples”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" }) // ""