@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
33 lines (32 loc) • 1.58 kB
TypeScript
import type { RelativeRoundingMethod } from "../../types/index.js";
type RelativeUnit = "year" | "month" | "week" | "day" | "hour" | "minute" | "second";
export interface FormatRelativeDateTimeOptions {
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-time and a reference date-time.
*
* - Auto-picks the display unit (second through year) based on the distance, unless
* `largestUnit` forces one.
* - `roundingMethod` controls how the distance rounds to the display unit.
*
* @param value ISO date-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 formatRelativeDateTime("2026-03-17T09:00:00", "en-GB", { style: "long" }) // "in 3 hours"
* @example formatRelativeDateTime(value, "en-US", { roundingMethod: "floor" }) // rounds toward the earlier boundary
* @example formatRelativeDateTime("not-a-date") // ""
*/
export declare function formatRelativeDateTime(value: string, locale?: string, options?: FormatRelativeDateTimeOptions): string;
export {};