UNPKG

@burglekitt/gmt

Version:

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

33 lines (32 loc) 1.51 kB
import type { RelativeRoundingMethod } from "../../types/index.js"; type RelativeUnit = "year" | "month" | "week" | "day"; export interface FormatRelativeDateOptions { style?: "long" | "short" | "narrow"; numeric?: "always" | "auto"; largestUnit?: RelativeUnit; /** * How the computed distance rounds to the display unit: "floor" rounds toward the * earlier boundary, "ceil" toward the later boundary, "round" (default) to the nearest — * matches current behavior when omitted. */ roundingMethod?: RelativeRoundingMethod; reference?: string; } /** * Format the relative time between a plain date and a reference date. * * - Auto-picks the display unit (day/week/month/year) based on the distance, unless * `largestUnit` forces one. * - `roundingMethod` controls how the distance rounds to the display unit. * * @param value ISO date string to format * @param locale optional: BCP 47 locale tag * @param options optional: { style, numeric, largestUnit, roundingMethod, reference } * @returns the formatted relative-time string, or "" on invalid input * * @example formatRelativeDate("2026-01-15", "en-US", { reference: "2026-04-15" }) // "3 months ago" * @example formatRelativeDate(value, "en-US", { roundingMethod: "floor" }) // rounds toward the earlier boundary * @example formatRelativeDate("not-a-date") // "" */ export declare function formatRelativeDate(value: string, locale?: string, options?: FormatRelativeDateOptions): string; export {};