@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
35 lines (34 loc) • 1.69 kB
TypeScript
import type { RelativeRoundingMethod } from "../../types/index.js";
type RelativeUnit = "year" | "month" | "week" | "day" | "hour" | "minute" | "second";
export interface FormatRelativeUnixOptions {
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;
epochUnit?: "milliseconds" | "seconds";
reference?: string | number;
timeZone?: string;
}
/**
* Format the relative time between a unix epoch value 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 unix epoch (string or number, per `epochUnit`) to format
* @param locale optional: BCP 47 locale tag
* @param options optional: { style, numeric, largestUnit, roundingMethod, epochUnit, reference, timeZone }
* @returns the formatted relative-time string, or "" on invalid input
*
* @example formatRelativeUnix(1710685845000, "en-US", { epochUnit: "milliseconds" }) // "3 years ago"
* @example formatRelativeUnix(value, "en-US", { roundingMethod: "floor" }) // rounds toward the earlier boundary
* @example formatRelativeUnix("not-a-number") // ""
*/
export declare function formatRelativeUnix(value: string | number, locale?: string, options?: FormatRelativeUnixOptions): string;
export {};