UNPKG

@burglekitt/gmt

Version:

Temporal-based date and time utilities with timezone support and polyfill integration

24 lines (23 loc) 1.44 kB
import { Temporal } from "@js-temporal/polyfill"; /** * 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. * * @param value ISO 8601 zoned datetime string * @param options Rounding options: smallestUnit, optional roundingIncrement, roundingMode * @returns Rounded ISO 8601 zoned datetime string, or "" on invalid input * * @example roundZoned("2024-06-15T12:34:56-05:00[America/New_York]", { smallestUnit: "hour" }) // "2024-06-15T13:00:00-05:00[America/New_York]" * @example 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]" * @example roundZoned("invalid", { smallestUnit: "hour" }) // "" */ export declare function roundZoned(value: string, options: { smallestUnit: Temporal.SmallestUnit<"day" | "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond">; roundingIncrement?: number; roundingMode?: Temporal.RoundingMode; }): string;