@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
34 lines (33 loc) • 1.57 kB
TypeScript
import type { RelativeRoundingMethod } from "../../types/index.js";
type RelativeUnit = "year" | "month" | "week" | "day" | "hour" | "minute" | "second";
export interface FormatRelativeUtcOptions {
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;
timeZone?: string;
}
/**
* Format the relative time between a UTC ISO string and a reference instant.
*
* - 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 UTC ISO string to format
* @param locale optional: BCP 47 locale tag
* @param options optional: { style, numeric, largestUnit, roundingMethod, reference, timeZone }
* @returns the formatted relative-time string, or "" on invalid input
*
* @example formatRelativeUtc("2024-03-17T14:30:45+00:00[UTC]", "en-US") // "2 years ago"
* @example formatRelativeUtc(value, "en-US", { roundingMethod: "floor" }) // rounds toward the earlier boundary
* @example formatRelativeUtc("not-a-date") // ""
*/
export declare function formatRelativeUtc(value: string, locale?: string, options?: FormatRelativeUtcOptions): string;
export {};