UNPKG

@burglekitt/gmt

Version:

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

27 lines (26 loc) 1.53 kB
import { Temporal } from "@js-temporal/polyfill"; import type { FractionalDigit } from "../../types/index.js"; /** * Round a UTC datetime string to the specified unit. * * - Converts to Instant, rounds, converts back to UTC Instant string. * - Supports: "hour", "minute", "second", "millisecond", "microsecond", "nanosecond". * - Date units ("year", "month", "week", "day") are not supported by the Temporal polyfill's Instant.round() — they return "". * - Wraps all Temporal calls in try-catch; returns "" on any error. * * @param value ISO UTC datetime string * @param options Rounding options: smallestUnit, optional roundingIncrement, roundingMode, fractionalSecondDigits * @returns Rounded ISO UTC Instant string, or "" on invalid input * * @example roundUtc("2024-06-15T12:34:56Z", { smallestUnit: "hour" }) // "2024-06-15T13:00:00Z" * @example roundUtc("2024-06-15T12:34:56Z", { smallestUnit: "minute", roundingIncrement: 15 }) // "2024-06-15T12:45:00Z" * @example roundUtc("2024-06-15T12:34:56Z", { smallestUnit: "second", roundingMode: "floor" }) // "2024-06-15T12:34:56Z" * @example roundUtc("invalid", { smallestUnit: "hour" }) // "" * @example roundUtc("", { smallestUnit: "hour" }) // "" */ export declare function roundUtc(value: string, options: { smallestUnit: Temporal.SmallestUnit<"hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond">; roundingIncrement?: number; roundingMode?: Temporal.RoundingMode; fractionalSecondDigits?: FractionalDigit; }): string;