Skip to content

formatCalendarUnix

formatCalendarUnix(value: string | number, locale?: string, options?: FormatCalendarUnixOptions): string
import { formatCalendarUnix } from "@northguild/gmt/unix/format";

Format a unix epoch value as a relative day label plus time-of-day, e.g.

  • “Tomorrow at 2:30 PM” — the unix counterpart of formatCalendar. See that function’s JSDoc for the day-label/threshold/connector design; this variant compares calendar days and renders the clock time in timeZone (default "UTC").
Parameter Type Description
value string | number unix epoch (string or number, per epochUnit) to format
locale string optional: BCP 47 locale tag

options

Option Type Default
epochUnit? "seconds" | "milliseconds"
reference? string | number
timeZone? string
timeStyle? "short" | "medium" | "full"

the formatted calendar string, or “” on invalid input

formatCalendarUnix(1710685845000, "en-US", { epochUnit: "milliseconds", timeZone: "America/New_York" }) // day label + time relative to "now", or the absolute fallback beyond the ±6-day threshold
formatCalendarUnix(value, "en-US", { reference: 1710685000000 }) // e.g. "tomorrow at 2:30 PM"
formatCalendarUnix("not-a-number") // ""

unix/format/formatCalendarUnix.ts