formatRelativeUtc
Signature
Section titled “Signature”formatRelativeUtc(value: string, locale?: string, options?: FormatRelativeUtcOptions): stringimport { formatRelativeUtc } from "@northguild/gmt/utc/format";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
largestUnitforces one. roundingMethodcontrols how the distance rounds to the display unit.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
UTC ISO string to format |
locale |
string |
optional: BCP 47 locale tag |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
style? |
"long" | "short" | "narrow" |
— |
numeric? |
"always" | "auto" |
— |
largestUnit? |
RelativeUnit |
— |
roundingMethod? |
RelativeRoundingMethod |
— |
reference? |
string |
— |
timeZone? |
string |
— |
Returns
Section titled “Returns”the formatted relative-time string, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”formatRelativeUtc("2024-03-17T14:30:45+00:00[UTC]", "en-US") // "2 years ago"formatRelativeUtc(value, "en-US", { roundingMethod: "floor" }) // rounds toward the earlier boundaryformatRelativeUtc("not-a-date") // ""