UNPKG

@burglekitt/gmt

Version:

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

33 lines (32 loc) 1.49 kB
import type { RelativeRoundingMethod } from "../../types/index.js"; type RelativeUnit = "hour" | "minute" | "second"; export interface FormatRelativeTimeOptions { 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 time and a reference time. * * - Auto-picks the display unit (second/minute/hour) based on the distance, unless * `largestUnit` forces one. * - `roundingMethod` controls how the distance rounds to the display unit. * * @param value ISO time 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 formatRelativeTime("14:30:00", "en-US", { style: "short" }) // "2 hr. ago" * @example formatRelativeTime(value, "en-US", { roundingMethod: "floor" }) // rounds toward the earlier boundary * @example formatRelativeTime("not-a-time") // "" */ export declare function formatRelativeTime(value: string, locale?: string, options?: FormatRelativeTimeOptions): string; export {};