UNPKG

@burglekitt/gmt

Version:

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

27 lines (26 loc) 1.22 kB
import { Temporal } from "@js-temporal/polyfill"; import type { DateUnit } from "../../types/index.js"; /** * Round an ISO 8601 date string to the specified date unit. * * - Returns "" for invalid inputs. * - Accepts date units: "year", "month", "week", "day". * - Time units ("hour", "minute", etc.) are rejected and return "". * - All date units use manual start-of-unit rounding. * - Wraps all Temporal calls in try-catch; returns "" on any error. * * @param value ISO 8601 date string * @param options Rounding options: smallestUnit, optional roundingIncrement and roundingMode * @returns Rounded ISO 8601 date string, or "" on invalid input * * @example roundDate("2024-06-15", { smallestUnit: "year" }) // "2024-01-01" * @example roundDate("2024-06-15", { smallestUnit: "month" }) // "2024-07-01" * @example roundDate("2024-06-15", { smallestUnit: "week" }) // "2024-06-16" * @example roundDate("2024-06-15", { smallestUnit: "day" }) // "2024-06-15" * @example roundDate("invalid", { smallestUnit: "year" }) // "" */ export declare function roundDate(value: string, options: { smallestUnit: DateUnit; roundingIncrement?: number; roundingMode?: Temporal.RoundingMode; }): string;