@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.
43 lines • 2.33 kB
TypeScript
import { Temporal } from "./temporal.js";
type Options = Intl.DateTimeFormatOptions;
/**
* Resolve caller options into runtime `Intl.DateTimeFormat` options that
* format an exact time in `timeZone`.
*
* - Returns `null` when the caller passed a `timeZone` option: the value is
* formatted in its own zone, and `Temporal.ZonedDateTime#toLocaleString`
* throws a TypeError for one (CreateDateTimeFormat with
* toLocaleStringTimeZone).
* - With no date or time field and no `dateStyle`/`timeStyle`, year, month,
* day, hour, minute and second default to `"numeric"`. With `defaults`
* `"zoned-date-time"` (ZonedDateTime#toLocaleString) `timeZoneName` also
* defaults to `"short"`; with `"all"` (an Instant) it does not.
*
* @param options caller's `Intl.DateTimeFormatOptions`
* @param timeZone the zone the value is formatted in
* @param defaults GetDateTimeFormat defaults: `"zoned-date-time"` or `"all"`
* @returns runtime options in `timeZone`, or `null` for a `timeZone` option
*/
export declare function instantFormatOptions(options: Options, timeZone: string, defaults: "zoned-date-time" | "all"): Options | null;
/**
* Format an exact time as text, either as its wall clock (a PlainDateTime) or
* as a ZonedDateTime with its zone, through the runtime's
* `Intl.DateTimeFormat`. Shared by `formatUtc` and `formatUnix`.
*
* - The wall-clock path uses {@link plainDateTimeFormatOptions}
* (GetDateTimeFormat ~any~, ~all~, ~relevant~): `timeZoneName` is not
* inherited.
* - The zoned path uses {@link instantFormatOptions} with
* `"zoned-date-time"` defaults.
* - `options` must not carry a `timeZone`; the zone comes from
* `zonedDateTime`. Constructing with `options` first surfaces the TypeError
* or RangeError Intl.DateTimeFormat raises for invalid ones.
*
* @param zonedDateTime the value in the zone it is rendered in
* @param locale BCP 47 locale, or `undefined` for the runtime default
* @param options caller's `Intl.DateTimeFormatOptions` without `timeZone`
* @param includeTimeZoneName `true` for the zoned path
* @returns the formatted text, not yet normalised
*/
export declare function formatWallClockOrZoned(zonedDateTime: Temporal.ZonedDateTime, locale: string | string[] | undefined, options: Options, includeTimeZoneName: boolean): string;
export {};