@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
50 lines • 3.13 kB
TypeScript
/**
* Options for `formatCalendarZoned`: the moment the day label is measured from and the length of
* the time-of-day half.
*/
export interface FormatCalendarZonedOptions {
/**
* The instant the day label is measured from, as a zoned ISO string, a UTC ISO string or a
* numeric epoch in milliseconds. Whatever its form, it is converted into `value`'s own time zone
* before calendar days are compared, because a day label needs one zone's wall clock and
* `value`'s zone is whose "today" is being described. Any other value returns `""`.
*
* @defaultValue The current instant, read in `value`'s time zone.
*/
reference?: string | number;
/**
* The length of the time-of-day part, as the `timeStyle` of `Intl.DateTimeFormat`. `"short"`
* writes hours and minutes, `"medium"` adds seconds, `"long"` adds the locale's short zone
* name ("BST" in en-GB, "GMT+1" in en-US) and `"full"` the long one ("British Summer Time" in
* English). Any other value returns `""`.
*
* @defaultValue `"short"`
*/
timeStyle?: "short" | "medium" | "long" | "full";
}
/**
* Format a zoned date-time as a relative day label plus time-of-day, e.g.
* "tomorrow at 14:30" — the zoned counterpart of `formatCalendar`. See
* that function's JSDoc for the day-label/threshold/connector design; this
* variant differs only in reading `value`'s IANA timezone for both the
* calendar-day comparison and the rendered clock time.
* - `options` must be an object or omitted: `null` or any other primitive returns `""`, as
* Temporal's GetOptionsObject rejects it.
* - A `chinese` or `dangi` date follows the observatory the standard names: Purple Mountain
* Observatory for `chinese`, KASI for `dangi`. A runtime that prints a different date for one of
* them returns `""` for any format with a year, month, day or era in that calendar. A runtime
* that prints the observatory's date keeps its own text. A format with only a time or weekday
* field always returns its text.
*
* @param value ZonedDateTime ISO string to format
* @param locale optional: BCP 47 locale tag, or a preference list of tags (ECMA-402)
* @param options optional settings for the reference moment and the time style
* @returns the formatted calendar string, or "" on invalid input
*
* @example formatCalendarZoned("2026-03-16T14:30:00+00:00[Europe/London]", "en-GB", { reference: "2026-03-15T09:00:00+00:00[Europe/London]" }) // "tomorrow at 14:30"
* @example formatCalendarZoned("2026-03-16T14:30:00+01:00[Europe/Berlin]", "de-DE", { reference: "2026-03-15T09:00:00+01:00[Europe/Berlin]" }) // "morgen um 14:30"
* @example formatCalendarZoned("not-a-date") // ""
* @example formatCalendarZoned("2024-03-16T14:30:00+02:00[Africa/Johannesburg]", ["fr-FR", "en-US"], { reference: "2024-03-15T09:00:00+02:00[Africa/Johannesburg]" }) // "demain à 14:30"
* @example formatCalendarZoned("2024-03-12T10:00:00+09:00[Asia/Tokyo]", "ja-JP", null as never) // "" (null options)
*/
export declare function formatCalendarZoned(value: string, locale?: string | string[], options?: FormatCalendarZonedOptions): string;